Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Function opposite of STREXTRACT()
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01573956
Message ID:
01574024
Vues:
37
>>Is there a function in VFP that will work to replace a string between two delimits? Just as STREXTRACT() allows to extract between two delimits, to write the changed string back.
>
>I think you are already following Sergey's good recommendation, but if in the future you want something similar that it is not XML (but you still have two delimiters) then you might be able to use regular expressions (depending what you want to do), for example:
>
>
>clear
>local loRE as 'VBScript.RegExp', lcString as String, lcNewText as String
>
>lcString	= '<TAG>this text will be replaced</TAG><SOMEOTHERTAG>This text remains unchanged</SOMEOTHERTAG><TAG>this text will be replaced too</TAG>'
>lcNewText	= 'this is the new text'
>loRE		= CreateObject('VBScript.RegExp')
>with loRE as VBScript.RegExp
>	.Pattern	= '(\<TAG\b[^\>]*\>)(.*?)(\<\/TAG\>)'
>	.Global		= .t.
>	.IgnoreCase	= .t.
>	if loRE.Test(lcString)
>		? .Replace(lcString, '$1' + lcNewText + '$3')
>	endif
>endwith
>
Thank you, Hugo. I will study your code; if anything then to learn. I have never understood how you guys create the RegExp patterns.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform