Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bug in GetWordNum
Message
De
14/08/2017 11:12:14
 
 
À
14/08/2017 10:35:48
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Divers
Thread ID:
01653264
Message ID:
01653284
Vues:
80
>>>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, ",")                     && returns "1"
>>>? GetWordNum( ",2,3", 1, ",")                       && returns "2"
>>>? GetWordNum( ",,3", 1, ",")                         && returns "3"
>>>
>>
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform