>>>Hi All,
>>>
>>>After nearly an hour of screaming, I discovered the source to a recent issue.
>>>There is a bug in GetWordNum(). If the string being searched begins with the delimiter, and you are requesting the first word, the function will return the Second word in the list.
>>>
>>>
>>>? GetWordNum( "1,2,3", 1, ",")
>>>? GetWordNum( ",2,3", 1, ",")
>>>? GetWordNum( ",,3", 1, ",")
>>>
>>
>>AFAIK, this is by design. If will return the nTh word. It will disregard empty words. For this reason I use STREXTRACT() in cases where empty words are possible
>
>I think the origin of the behavior can be traced to extracting words from text files, where, back in the DOS days, the columns were often made by padding the strings with spaces. Poor man's formatting. Likewise, text justification was achieved by inserting spaces between words. And then a getwordnum() which would be sensitive to multiple spaces and return "" for each - well that would have pissed us all off back then, wouldn't it?
I believe it has all to do with word delimiters (like punctuation) being possible in any number, in any order, and anywhere around a word. That's why delimiters in functions that work on patterns of strings, probably according to some format, like ALINES(), STREXTRACT(), ALLTRIM(), etc., are string based, and GETWORD*() delimiters are character (that is, symbol) based.
LOCAL Source AS String
LOCAL WordDelimiters AS String
LOCAL WordIndex AS Integer
m.Source = "I think the origin of the behavior can be traced to extracting words from text files, where, back in the DOS days, the columns were often made by padding the strings with spaces."
m.WordDelimiters = " ,.:;?!-" + CHR(13) + CHR(10) + CHR(9)
FOR m.WordIndex = 1 TO GETWORDCOUNT(m.Source, m.WordDelimiters)
? GETWORDNUM(m.Source, m.WordIndex, m.WordDelimiters)
ENDFOR
----------------------------------
António Tavares Lopes