Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Misleading StrTran() help
Message
From
19/11/2002 13:31:49
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro Product Documentation
Title:
Misleading StrTran() help
Miscellaneous
Thread ID:
00724428
Message ID:
00724428
Views:
55
I ran into a problem with the StrTran() function which, IMHO, was caused by the poor wording of the documentation. My misunderstanding has now been cleared up thanks to Rick Bean, but I think it is worth MS having a look at this and cleaning up the documentation for this command.

It has to do with the nFlags parameter and how it works.

The syntax statement is as follows:
STRTRAN(cSearched, cExpressionSought [, cReplacement]
        [, nStartOccurrence] [, nNumberOfOccurrences] [, nFlags])
nFlags = 3 is supposed to mean (and this is directly from the help):
Search is case-insensitive; case of cReplacement is changed to match the case of cExpressionSought, which it replaces.
It seems (seemed) clear to me that changed to match the case of cExpressionSought meant that if, for instance, cExpressionSought were upper case, then cReplacement would be changed to be upper case.

Therefor:
lcString = 'abracadabra'
? StrTran(lcString, 'A', 'x', 1, 500, 3)
Should display
XbrXcXdXbrX
(ie) cReplacement ('x') is changed to match the case of cExpressionSought ('A'), but as it turns out, that is not what happens.

Instead, it returns
xbrxcxdxbrx
What is actually happening, is that the case of 'x' is being changed to match the case of the string which it is replacing as it is found in cSearched ('abracadabra'), where the 'a's are all lower case.

It seems to me that the description of how nFlag = 3 should work would make more sense as:
Search is case-insensitive; case of cReplacement is changed to match the case of the string in cSearched which it replaces.
It's a small change; only a couple of words, but I think it makes a huge difference.

Alan
Next
Reply
Map
View

Click here to load this message in the networking platform