GetWordCount(), GetWordNum()
These two functions represent another step in moving the most useful items from FoxTools into the core language. GetWordCount() takes a string and tells you how many words it contains. GetWordNum() returns a specified word from a string.
Usage |
nWords = GETWORDCOUNT( cString [, cDelimiters ] ) cWord = GETWORDNUM( cString, nWord [, cDelimiters ] ) |
Parameter |
Value |
Meaning |
cString |
Character |
The string to be parsed. |
cDelimiters |
Character |
A list of characters to use as word separators. |
Omitted |
Words are separated by space, tab (CHR(9)) and linefeed (CHR(10)). |
|
nWord |
Positive number |
Return the specified word from the string. If there aren't that many words in the string, return the empty string. |
0 or negative number |
Return the empty string. |
|
nWords |
Numeric |
The number of words in the string, based on the specified separators. |
cWord |
Character |
The specified word from the string. |
Like ALINES(), these functions aren't limited to thinking about only the conventional ways of dividing up strings. You can specify whatever word separators you want by passing the optional cDelimiters parameter, making the functions useful for generic processing. (You can even specify letters or digits.) However, ALINES() is much, much faster, so we don't see ourselves using these two functions that way a lot. |
Example |
? GETWORDCOUNT("Now is the time for all good men") && Returns 8 ? GETWORDCOUNT("Red,yellow,blue",",") && Returns 3 ? GETWORDCOUNT("Red, yellow and blue", ",") && Returns 2 ? GETWORDCOUNT("Red, yellow and blue",", ") && Returns 4 ? GETWORDNUM("Now is the time for all good men", 2) && Returns "is" ? GETWORDNUM("Red,yellow,blue",3,",") && Returns "blue" ? GETWORDNUM("Red, yellow and blue", 2, ",") && Returns " yellow and blue" ? GETWORDNUM("Red, yellow and blue", 2, ", ") && Returns "yellow" |
See Also |