Re: script for multi text replacement

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"tonycd" <tonycd@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:492FF849-8C13-4951-A9CE-4F9BD19D3624@xxxxxxxxxxxxxxxx
Thanks AI Dunbar

Would you please explain more. I really don't understand. Thanks

You're welcome.

The dictionary object is described in script56.chm and at the script center. I'd suggest you read up n it and ask specific questions about its use here.

/Al

"Al Dunbar" wrote:


"ekkehard.horner" <ekkehard.horner@xxxxxxxx> wrote in message
news:4a368299$0$31864$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> tonycd schrieb:
> [...]
>> But how can i enhance the script for multi - text replacement.
> [...]
> To make it easy to experiment with the aspects pointed out by
> the other contributors (and to add an array/loop based approach):
>
> demo script:
>
> Dim sSrc : sSrc = "one two three ONE TWO THREE one two three"
> Dim sTrg

<snip>

> Dim aRpl( 1, 2 )
> Dim nRpl
> aRpl( 0, 0 ) = "one"
> aRpl( 1, 0 ) = "eins"
> aRpl( 0, 1 ) = "two"
> aRpl( 1, 1 ) = "zwei"
> aRpl( 0, 2 ) = "three"
> aRpl( 1, 2 ) = "drei"
>
> sTrg = sSrc
> For nRpl = 0 To UBound( aRpl, 2 )
> sTrg = Replace( sTrg, aRpl( 0, nRpl ), aRpl( 1, nRpl ) )
> Next
> WScript.Echo Join( Array( "looped repl, all, honor case", sSrc, sTrg,
> "" ), vbCrLf )

That is a definite improvement over a series of calls to the replace
function. But a dictionary object might be better suited for holding the
strings to be changed from/to than an array:

dim aRpl
ser aRpl = createobject("scripting.dictionary")
aRpl("one") = "eins"
aRpl("two") = "zwei"
aRpl("three") = "drei"
sTrg = sSrc
For each key in aRpl.keys
sTrg = Replace( sTrg, key, aRpl(key))
Next

/Al

<snip>






.



Relevant Pages