ALines()
This function, added in VFP 6, lets you take character or memo data and dump it into an array, one line per array element. It's faster and easier than using MLINE() and _MLINE for the task. Though each of the two approaches has advantages and disadvantages, the additional functionality added in VFP 7 confirms ALINES() as our first choice for many parsing tasks.
Usage |
nLineCount = ALINES( DestArray, cString [, lTrimIt ] [ cParseChar1, � cParseCharn ] ) |
Parameter |
Value |
Meaning |
DestArray |
Array Name |
The array to contain the character or memo data. |
cString |
Memo or Character |
The string to be broken into lines. Can be a character or memo field or any character expression. |
lTrimIt |
.T. |
Remove leading and trailing blanks from each line. |
.F. or Omitted |
Leave leading and trailing blanks on lines. |
|
ParseCharx |
Character |
One or more characters to be treated as line breaks. |
nLineCount |
Numeric |
The number of lines in cString, which is the same as the number of rows created in DestArray. |
Our favorite use for ALINES() is parsing lists of things. For example: cColors = "Red, Orange, Yellow, Green, Blue, Purple" nItems = ALINES( aColors, cColors, .T., ",") That code requires VFP 7 or later, but you can do the same thing in VFP 6 by including STRTRAN() in the mix: cColors = "Red, Orange, Yellow, Green, Blue, Purple" nItems = ALINES( aColors, STRTRAN(cColors, ",", CHR(13)), .T.) |
Example |
* Assume mField is a memo field. = ALINES(aAllLines, mField, .T.) * Or use this with a string. nLines = ALINES(aAllLines, "Here is a string composed of " + ; "several lines."+ ; CHR(13)+"Here's the second line." + ; CHR(10)+"Here's the third line."+ ; CHR(13)+CHR(10)+"Notice that it doesn't "+ ; "matter which line break character you use.") |
See Also |
GetWordCount(), GetWordNum(), MemLines(), MLine(), _MLine, Set MemoWidth, StrExtract(), StrTran() |