Wiki Home


Namespace: WIN_COM_API
ALINES( array_name, c_expression [, l_trim])
VFP 9: ALINES(ArrayName, cExpression [, nFlags] [, cParseChar [, cParseChar2 [, ...]]])

see the revisions for VFP9 in the VFP Help.

ALINES() copies each line in a character expression or memo field to a corresponding row in an array and returns the number of lines copied.

Interesting notes:
For performance measurements, see Topic: Traversing Text
Cool Tip: To parse a line of text into it's component words without going through the trouble of using Fox Tools:
lnWords = alines( laWords, chrtran( lcStr, ' ', chr(13) ), .t. )

You do have to test for empty array elements if your string has contiguous spaces in it.
Trap: Successive lines with only CHR(13) carriage returns are considered as one line. For example:
lcSource = "How~~Many~~Lines?~"
lcString = STRTRAN(lcSource,"~",CHR(13))
?ALINES(aParms,lcstring)   && 3

But if you use carriage return + line feed, CHR(13)+CHR(10), you’ll get the results you expect.
lcSource = "How~~Many~~Lines?~"
lcString = STRTRAN(lcSource,"~",CHR(13)+CHR(10))
?ALINES(aParms,lcstring)   && 5

Steve - but if you are only concerned with the "words" in the string then it's not a real trap. -- ?df
Well, this has to do with lines, and depending on how they are formed, blank lines may or may not show up. This may or may not matter depending on the situation. That's the trap.
Here are some tests proving the new 'cParseChar' parameter (name in help) is indeed a terminator as noted in help details. I'm posting this here because the first and third test results aren't what I expected. Joe Kuhn

TestAlines("", 1, "$")
TestAlines("$", 1, "$")
TestAlines("$ ", 2, "$")
TestAlines(" $", 1, "$")

FUNCTION TestAlines(tcStr, tnExpectedCount, tcTerminator)
LOCAL lnCount
	lnCount = ALINES(la, tcStr, .F., tcTerminator)
	ASSERT lnCount = tnExpectedCount MESSAGE "Expected " + TRANSFORM(tnExpectedCount) + ", Got " + TRANSFORM(lnCount)

Contributors: Randy Pearson, Michael GEmmons David Frankenbach Steven Black
Category VFP Functions
( Topic last updated: 2006.12.07 08:00:45 PM )