Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with strtran()
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00414505
Message ID:
00414704
Vues:
19
>I have a large rtf file (~300KB) with a bunch of "slugs" in it. What I mean by slugs are variables surrounded by "<<" and ">>". So the file would look something like :
>
>blah blah blah <> blah blah
>
>
>I use filetostr to put the entire file into a string then I use strtran to find and replace the slugs with values. The problem is that strtran doesn't seem to replacing all the slugs. It will replace some of them but not all even when the slugs are exactly the same.
>

You can always use the VBScript.RegExp object if you can't figure out how to use STRTRAN():
cMyString = FILETOSTR('MyFileToXlate.RTF')
oRegExp = CREATEOBJ('VBScript.RegExp')
oRegExp.Global = .t.  && allow find of more than one occurance
oRegExp.IgnoreCase = .t.  && make search case-insensitive
oRegExp.Pattern = '<<SomeString>>'  && what to find - can include regular expressions
cMyString = oRegExp.Replace(cMyString,'what I want for this slug') && replace each with specified value
oRegExp.Pattern = '<<Another Slug>>'
cMyString = oRegExp.Replace(cMyString,'what I want for this paticular slug')
* yada, yada, yada
=STRTOFILE(cMyString,'MyXlatedFile.RTF')
It's part of WSH version 2.0 or later; see the refs in my sig block for details. You can get fancy and use regular expressions, to the extent of coding up something that strips out your 'slug' and macro-expands the variable referenced by the slug content - you'll have to write this for yourself.
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform