Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
StrTran() - any known limitations?
Message
De
31/10/2007 09:16:41
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
31/10/2007 08:56:39
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 SP1
OS:
Windows XP SP1
Divers
Thread ID:
01265319
Message ID:
01265336
Vues:
10
>I have this piece of code
>
>
Function StrWhile(tcStr, tcRepl, tcReplWith)
>Do While Atc(tcRepl, tcStr)>0 And tcRepl#tcReplWith
>	tcStr2=Strtran(tcStr, tcRepl, tcReplWith)
>	If tcStr2==tcStr
>		Exit
>	Else
>		tcStr=tcStr2
>	Endif
>Enddo
>Return tcStr
>
>The reason I have this if/else block is that it sometimes doesn't replace the string. I've set the watch on the atc() expression, and it remains unchanged, somewhere about 200K or more.
>
>Is there a known bug or limitation that would make StrTran() not work sometimes - when a string is too long or under any other weird circumstances?

Dragan,
Other than casesensitivity I didn't see something related to strtran(). However wouldn't this code be much easier and faster with RegExp searches? It'd be a single Replace call. ie:
TEXT TO lcSample noshow
Hi Dragan, how are you?DRagan how are you?
Dragandrop interface.
endtext
? StrWhile(m.lcSample,"\bDragan\b","Cetin")
? StrWhile(m.lcSample,"dragan","Cetin")

FUNCTION StrWhile(tcStr, tcRepl, tcReplWith)
oRX = Createobject("VBScript.RegExp")
With oRX
  .Pattern = m.tcRepl
  .IgnoreCase = .T.
  .Global = .T.
ENDWITH
RETURN oRX.Replace(m.tcStr, m.tcReplWith)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform