Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug in GetWordNum
Message
From
14/08/2017 12:09:47
 
 
To
14/08/2017 07:15:39
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01653264
Message ID:
01653285
Views:
56
I have misunderstood the behavior of the function (all these years). I thought it simple parsed the string as a delimited string, but instead it returns the nth word of the string using the delimiter as a break point. Something like if I was to ask for the 1st word of the string " This is a test " with space being the delimiter. After trimming the leading delimiters, the first word would then be 'This'.

I have been using GetWordNum since it was in FoxTools.fll. But now I need to rethink how it is to be used.

I see a SHIT load of unit testing ahead of me.

Thank you all for the insight.



>How this address the question of your original post?
>
>Quote: 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.
>
>>Yes, this may be better then ALINES solution
>>
>>
>>>The behavior you describe is the designed behavior -- not what I wanted either. In the case of a delimited string such as
>>>
>>>
>>>lcString = "test1|test2||test4"
>>>
>>>
>>>I would want the third word to be empty; however, GETWORDNUM() returns test4 as the third word and GETWORDNUM() returns 3, instead of 4. If you do a string translation first and insert a space in a null place:
>>>
>>>
>>>lcString = "test1|test2||test4"
>>>DO WHILE ATC("||", lcString) > 0
>>>   lcString = STRTRAN(lcString, "||", , "| |")
>>>ENDDO
>>>lcThird = GETWORDNUM(lcString, 3, "|")
>>>
>>>
>>>Now you will get the results that you expect.
Greg Reichert
Previous
Reply
Map
View

Click here to load this message in the networking platform