Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Case insensitve Strtran
Message
From
21/12/2000 22:03:36
 
 
To
21/12/2000 05:32:29
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00455364
Message ID:
00456167
Views:
32
>Hi Ed,
>
>This is the solution I came up with - I think this one works a bit better because if the string you are searching for is contained in the replacement string things will get confusing 8-)
>eg lcVar = StrtrannoCase(lcVar, 'Proc', 'Procedure')
>
>
>lParameters tcStr, tcFind, tcRep
>Local lnPos
>
>lnPos = ATC(tcFind, tcStr)
>Do While lnPos > 0
> tcStr = STUFF( tcStr, lnPos, LEN(tcFind), '*!*SomeUniqueString*!*')
> lnPos = ATC(tcFind, tcStr)
>EndDo
>
>Return Strtran(tcStr, '*!*SomeUniqueString*!*', tcRep)

If you want this behavior, you might try:
lParameters tcStr, tcFind, tcRep
Local lnPos, lcResult, lcRemainder, lnLenFind
lcRemainder = tcStr
lnPos = ATC(tcFind, lcRemainder)
lnLenFind = LEN(tcFind)
lcResult = ''
Do While lnPos > 0
   lcResult = lcResult + LEFT(lcRemainder, lnPos - 1) + tcRep
   lcRemainder = SUBST(lcRemainder,lnPos + lnLenFind)
   lnPos = ATC(tcFind, lcRemainder)
EndDo
RETURN lcResult + lcRemainder
but VBScript.RegExp is far more powerful, and does the same thing by:
oRegExp = CREATEOBJ)'VBScript.RegExp')
oRegExp.Global = .t.
oRegExp.IgnoreCase = .t.
oRegExp.Pattern = tcFind
&& This configures the COM object - the next line does the translation
&& and may be called repeatedly without reinitializing the object.
lcResult = oRegExp.Replace(tcStr,tcRep)
and the regular expression parser supports a wide range of wildcarding, explicit positional scoping and control of string context. You can find details about it at the WSH sites from my sig block.




Return Strtran(tcStr, '*!*SomeUniqueString*!*', tcRep)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform