Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - script for multi text replacement

Reply
 
Old 06-16-2009   #11 (permalink)
tonycd


 
 

Re: script for multi text replacement

Hi Pegasus

Thanks all. But i really don't know what Paul said. Tony

"Pegasus [MVP]" wrote:
Quote:

> I quote from Paul Randall's reply (which he copied from script56.chm):
>
> ================
> Optional. Number of substring substitutions to perform. If omitted, the
> default value is -1, which means make all possible substitutions. Must be
> used in conjunction with start.
>
> ================
>
> In other words, *all* matching strings will be replaced. Why don't you give
> it a try?
>
>
> "tonycd" <tonycd@xxxxxx> wrote in message
> news:44689407-F42D-4CA9-AC49-0B94B3DF877F@xxxxxx
Quote:

> > Hi Pegasus
> >
> > thanks for your help again. As i mentioned before . i need to replace from
> > "event no." to "event description" from audit logon report. So more than
> > ten
> > "event no." that i need to replace. Would you please help ..Thanks
> >
> > regards
> > Tony
> >
> > "Pegasus [MVP]" wrote:
> >
Quote:

> >> Sorry, can't understand "What if i need to replace the text more than
> >> ten" -
> >> please rephrase.
> >>
> >>
> >> "tonycd" <tonycd@xxxxxx> wrote in message
> >> news:69C4CC27-9A58-41F3-830F-3FC5972B4F55@xxxxxx
> >> > Thanks all
> >> >
> >> > What if i need to replace the text more than ten. Thanks again
> >> > regards
> >> > Tony
> >> >
> >> > "Paul Randall" wrote:
> >> >
> >> >>
> >> >> "tonycd" <tonycd@xxxxxx> wrote in message
> >> >> news:74DABA76-6B73-4153-9926-2726ABF13D41@xxxxxx
> >> >> > Hi
> >> >> >
> >> >> > I just copy the script from Microsoft web site that for replace the
> >> >> > text.
> >> >> > But how can i enhance the script for multi - text replacement.
> >> >> > Thanks
> >> >> > i try with this (i put the star in front of script) , but it doesn't
> >> >> > work.
> >> >> >
> >> >> > regards
> >> >> > Tony
> >> >> >
> >> >> > Const ForReading = 1
> >> >> > Const ForWriting = 2
> >> >> >
> >> >> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >> >> > Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
> >> >> >
> >> >> > strText = objFile.ReadAll
> >> >> > objFile.Close
> >> >> > strNewText = Replace(strText, "Jim ", "James ")
> >> >> > ****strNewText = Replace(strText, "abc ", "apple ")
> >> >> >
> >> >> > Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
> >> >> > objFile.WriteLine strNewText
> >> >> > objFile.Close
> >> >>
> >> >> You probably already have file script56.chm on your computer. If not,
> >> >> go
> >> >> to
> >> >> msdn.microsoft.com's download tab and search for and download it, and
> >> >> read
> >> >> up on the replace function.
> >> >>
> >> >> It says that there are potentially more parameters for the replace
> >> >> function:
> >> >> Replace Function
> >> >> See Also
> >> >> Filter Function
> >> >> Requirements
> >> >> Version 2
> >> >> Returns a string in which a specified substring has been replaced with
> >> >> another substring a specified number of times.
> >> >>
> >> >> Replace(expression, find, replacewith[, start[, count[, compare]]])
> >> >> Arguments
> >> >> expression
> >> >> Required. String expression containing substring to replace.
> >> >> find
> >> >> Required. Substring being searched for.
> >> >> replacewith
> >> >> Required. Replacement substring.
> >> >> start
> >> >> Optional. Position within expression where substring search is to
> >> >> begin.
> >> >> If
> >> >> omitted, 1 is assumed. Must be used in conjunction with count.
> >> >> count
> >> >> Optional. Number of substring substitutions to perform. If omitted,
> >> >> the
> >> >> default value is -1, which means make all possible substitutions. Must
> >> >> be
> >> >> used in conjunction with start.
> >> >> compare
> >> >> Optional. Numeric value indicating the kind of comparison to use when
> >> >> evaluating substrings. See Settings section for values. If omitted,
> >> >> the
> >> >> default value is 0, which means perform a binary comparison.
> >> >>
> >> >> -Paul Randall
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

My System SpecsSystem Spec
Old 06-16-2009   #12 (permalink)
Al Dunbar


 
 

Re: script for multi text replacement


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:4a368299$0$31864$9b4e6d93@xxxxxx-online.net...
Quote:

> tonycd schrieb:
> [...]
Quote:

>> 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>
Quote:

> 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>


My System SpecsSystem Spec
Old 06-16-2009   #13 (permalink)
Pegasus [MVP]


 
 

Re: script for multi text replacement


"tonycd" <tonycd@xxxxxx> wrote in message
news:E33E0953-02A5-4E2B-A522-3D41161FD53B@xxxxxx
Quote:

> Hi Pegasus
>
> Thanks all. But i really don't know what Paul said. Tony
>
Which part is it that you do not understand?


My System SpecsSystem Spec
Old 06-16-2009   #14 (permalink)
tonycd


 
 

Re: script for multi text replacement

Thanks AI Dunbar

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

"Al Dunbar" wrote:
Quote:

>
> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
> news:4a368299$0$31864$9b4e6d93@xxxxxx-online.net...
Quote:

> > tonycd schrieb:
> > [...]
Quote:

> >> 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>
>
Quote:

> > 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>
>
>
>
My System SpecsSystem Spec
Old 06-16-2009   #15 (permalink)
Paul Randall


 
 

Re: script for multi text replacement

Hi, Tony
Default securty has been increased with recent OSs and their service packs.
Now when you download help files like script56.chm, WXP very stupidly
displays the left pane properly and displays completely misleading
information in the right pane. There is nothing wrong with the file. The
OS just doesn't trust it. So right click the downloaded script56.chm and
choose properties.
Near the bottom of the properties window, you will probably see a Security
entry that says this file came from another computer and might be blocked to
help
protect this computer, followed by an "Unblock" button. After you click
the Unblock button and choose 'apply', this security info area is grayed out
or is removed. The help file should then open and display properly with no
questions asked.

-Paul Randall

"tonycd" <tonycd@xxxxxx> wrote in message
newsEED1B89-C091-466C-90EE-F1D4E3D33F0A@xxxxxx
Quote:

> Thanks All
>
> I can't retrieve the script56.chm after download. (no contect at the right
> hand side).
> Would i use simple vbs instead as below. Thanks
>
> dim a
> dim b
> dim c
> document.write(Replace(a,"538","logoff"))
> document.write(Replace(b,"540","logon"))
> document.write(Replace(b,"528","logon"))
>
>
> "ekkehard.horner" wrote:
>
Quote:

>> tonycd schrieb:
>> [...]
Quote:

>> > 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
>>
>> ' Replace( expression, find, replacewith [, start (1) [, count (-1) [,
>> compare
>> (vbBinaryCompare) ) ] ] ] )
>>
>> sTrg = Replace( sSrc, "one" , "eins" )
>> sTrg = Replace( sTrg, "two" , "zwei" )
>> sTrg = Replace( sTrg, "three", "drei" )
>> WScript.Echo Join( Array( "sequential repl, all, honor case", sSrc,
>> sTrg, "" ), vbCrLf )
>>
>> sTrg = Replace( sSrc, "one" , "eins", 1, -1, vbTextCompare )
>> sTrg = Replace( sTrg, "two" , "zwei", 1, -1, vbTextCompare )
>> sTrg = Replace( sTrg, "three", "drei", 1, -1, vbTextCompare )
>> WScript.Echo Join( Array( "sequential repl, all, ignore case", sSrc,
>> sTrg, "" ), vbCrLf )
>>
>> sTrg = Replace( sSrc, "one" , "eins", 1, 1, vbBinaryCompare )
>> sTrg = Replace( sTrg, "two" , "zwei", 1, 1, vbBinaryCompare )
>> sTrg = Replace( sTrg, "three", "drei", 1, 1, vbBinaryCompare )
>> WScript.Echo Join( Array( "sequential repl, just one, ignore case",
>> sSrc, sTrg, "" ),
>> vbCrLf )
>>
>> sTrg = Replace( Replace( Replace( sSrc, "one", "eins" ), "two",
>> "zwei" ), "three", "drei" )
>> WScript.Echo Join( Array( "nested repl, all, honor case", sSrc, sTrg,
>> "" ), vbCrLf )
>>
>> sTrg = Replace( Replace( Replace( sSrc, "one", "eins", 1, 2,
>> vbTextCompare ), "two",
>> "zwei", 1, 2, vbTextCompare ), "three", "drei", 1, 2, vbTextCompare )
>> WScript.Echo Join( Array( "nested repl, just two, ignore case", sSrc,
>> sTrg, "" ), vbCrLf )
>>
>> 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 )
>>
>> sTrg = sSrc
>> For nRpl = 0 To UBound( aRpl, 2 )
>> sTrg = Replace( sTrg, aRpl( 0, nRpl ), aRpl( 1, nRpl ), 1, -1,
>> vbTextCompare )
>> Next
>> WScript.Echo Join( Array( "looped repl, all, ignore case", sSrc, sTrg,
>> "" ), vbCrLf )
>>
>> sTrg = replaceAll( sSrc, aRpl )
>> WScript.Echo Join( Array( "repl func, all, honor case", sSrc, sTrg,
>> "" ), vbCrLf )
>>
>> sTrg = replaceAllP( sSrc, aRpl, 2, vbTextCompare )
>> WScript.Echo Join( Array( "repl func parm, just two, ignore case",
>> sSrc, sTrg, "" ),
>> vbCrLf )
>>
>> sTrg = Replace( sSrc, "one" , "eins", 5, -1, vbTextCompare )
>> WScript.Echo Join( Array( "one repl, all, ignore case, starting at 5",
>> sSrc, sTrg, ""
>> ), vbCrLf )
>>
>> Function replaceAll( sSrc, aRpl )
>> replaceAll = sSrc
>> Dim nRpl
>> For nRpl = 0 To UBound( aRpl, 2 )
>> replaceAll = Replace( replaceAll, aRpl( 0, nRpl ), aRpl( 1,
>> nRpl ) )
>> Next
>> End Function
>>
>> Function replaceAllP( sSrc, aRpl, nCount, vbComp )
>> replaceAllP = sSrc
>> Dim nRpl
>> For nRpl = 0 To UBound( aRpl, 2 )
>> replaceAllP = Replace( replaceAllP, aRpl( 0, nRpl ), aRpl( 1,
>> nRpl ), 1, nCount,
>> vbComp )
>> Next
>> End Function
>>
>> output:
>>
>> === replDemo04: Replace Demo (04) =============================
>> sequential repl, all, honor case
>> one two three ONE TWO THREE one two three
>> eins zwei drei ONE TWO THREE eins zwei drei
>>
>> sequential repl, all, ignore case
>> one two three ONE TWO THREE one two three
>> eins zwei drei eins zwei drei eins zwei drei
>>
>> sequential repl, just one, ignore case
>> one two three ONE TWO THREE one two three
>> eins zwei drei ONE TWO THREE one two three
>>
>> nested repl, all, honor case
>> one two three ONE TWO THREE one two three
>> eins zwei drei ONE TWO THREE eins zwei drei
>>
>> nested repl, just two, ignore case
>> one two three ONE TWO THREE one two three
>> eins zwei drei eins zwei drei one two three
>>
>> looped repl, all, honor case
>> one two three ONE TWO THREE one two three
>> eins zwei drei ONE TWO THREE eins zwei drei
>>
>> looped repl, all, ignore case
>> one two three ONE TWO THREE one two three
>> eins zwei drei eins zwei drei eins zwei drei
>>
>> repl func, all, honor case
>> one two three ONE TWO THREE one two three
>> eins zwei drei ONE TWO THREE eins zwei drei
>>
>> repl func parm, just two, ignore case
>> one two three ONE TWO THREE one two three
>> eins zwei drei eins zwei drei one two three
>>
>> one repl, all, ignore case, starting at 5
>> one two three ONE TWO THREE one two three
>> two three eins TWO THREE eins two three
>>
>> === replDemo04: 0 done (00:00:00) =============================
>>
>> The last test case is included to show that using the start
>> parameter should be avoided in multi-text replacements.
>>
>>

My System SpecsSystem Spec
Old 06-17-2009   #16 (permalink)
Al Dunbar


 
 

Re: script for multi text replacement


"tonycd" <tonycd@xxxxxx> wrote in message
news:492FF849-8C13-4951-A9CE-4F9BD19D3624@xxxxxx
Quote:

> 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
Quote:

> "Al Dunbar" wrote:
>
Quote:

>>
>> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
>> news:4a368299$0$31864$9b4e6d93@xxxxxx-online.net...
Quote:

>> > 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>
>>
Quote:

>> > 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>
>>
>>
>>


My System SpecsSystem Spec
Old 06-21-2009   #17 (permalink)
tonycd


 
 

Re: script for multi text replacement

Thanks all. I put the replacement script inside the loop (someone taught me)
and it works.

regards
Tony

"Paul Randall" wrote:
Quote:

> Hi, Tony
> Default securty has been increased with recent OSs and their service packs.
> Now when you download help files like script56.chm, WXP very stupidly
> displays the left pane properly and displays completely misleading
> information in the right pane. There is nothing wrong with the file. The
> OS just doesn't trust it. So right click the downloaded script56.chm and
> choose properties.
> Near the bottom of the properties window, you will probably see a Security
> entry that says this file came from another computer and might be blocked to
> help
> protect this computer, followed by an "Unblock" button. After you click
> the Unblock button and choose 'apply', this security info area is grayed out
> or is removed. The help file should then open and display properly with no
> questions asked.
>
> -Paul Randall
>
> "tonycd" <tonycd@xxxxxx> wrote in message
> newsEED1B89-C091-466C-90EE-F1D4E3D33F0A@xxxxxx
Quote:

> > Thanks All
> >
> > I can't retrieve the script56.chm after download. (no contect at the right
> > hand side).
> > Would i use simple vbs instead as below. Thanks
> >
> > dim a
> > dim b
> > dim c
> > document.write(Replace(a,"538","logoff"))
> > document.write(Replace(b,"540","logon"))
> > document.write(Replace(b,"528","logon"))
> >
> >
> > "ekkehard.horner" wrote:
> >
Quote:

> >> 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
> >>
> >> ' Replace( expression, find, replacewith [, start (1) [, count (-1) [,
> >> compare
> >> (vbBinaryCompare) ) ] ] ] )
> >>
> >> sTrg = Replace( sSrc, "one" , "eins" )
> >> sTrg = Replace( sTrg, "two" , "zwei" )
> >> sTrg = Replace( sTrg, "three", "drei" )
> >> WScript.Echo Join( Array( "sequential repl, all, honor case", sSrc,
> >> sTrg, "" ), vbCrLf )
> >>
> >> sTrg = Replace( sSrc, "one" , "eins", 1, -1, vbTextCompare )
> >> sTrg = Replace( sTrg, "two" , "zwei", 1, -1, vbTextCompare )
> >> sTrg = Replace( sTrg, "three", "drei", 1, -1, vbTextCompare )
> >> WScript.Echo Join( Array( "sequential repl, all, ignore case", sSrc,
> >> sTrg, "" ), vbCrLf )
> >>
> >> sTrg = Replace( sSrc, "one" , "eins", 1, 1, vbBinaryCompare )
> >> sTrg = Replace( sTrg, "two" , "zwei", 1, 1, vbBinaryCompare )
> >> sTrg = Replace( sTrg, "three", "drei", 1, 1, vbBinaryCompare )
> >> WScript.Echo Join( Array( "sequential repl, just one, ignore case",
> >> sSrc, sTrg, "" ),
> >> vbCrLf )
> >>
> >> sTrg = Replace( Replace( Replace( sSrc, "one", "eins" ), "two",
> >> "zwei" ), "three", "drei" )
> >> WScript.Echo Join( Array( "nested repl, all, honor case", sSrc, sTrg,
> >> "" ), vbCrLf )
> >>
> >> sTrg = Replace( Replace( Replace( sSrc, "one", "eins", 1, 2,
> >> vbTextCompare ), "two",
> >> "zwei", 1, 2, vbTextCompare ), "three", "drei", 1, 2, vbTextCompare )
> >> WScript.Echo Join( Array( "nested repl, just two, ignore case", sSrc,
> >> sTrg, "" ), vbCrLf )
> >>
> >> 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 )
> >>
> >> sTrg = sSrc
> >> For nRpl = 0 To UBound( aRpl, 2 )
> >> sTrg = Replace( sTrg, aRpl( 0, nRpl ), aRpl( 1, nRpl ), 1, -1,
> >> vbTextCompare )
> >> Next
> >> WScript.Echo Join( Array( "looped repl, all, ignore case", sSrc, sTrg,
> >> "" ), vbCrLf )
> >>
> >> sTrg = replaceAll( sSrc, aRpl )
> >> WScript.Echo Join( Array( "repl func, all, honor case", sSrc, sTrg,
> >> "" ), vbCrLf )
> >>
> >> sTrg = replaceAllP( sSrc, aRpl, 2, vbTextCompare )
> >> WScript.Echo Join( Array( "repl func parm, just two, ignore case",
> >> sSrc, sTrg, "" ),
> >> vbCrLf )
> >>
> >> sTrg = Replace( sSrc, "one" , "eins", 5, -1, vbTextCompare )
> >> WScript.Echo Join( Array( "one repl, all, ignore case, starting at 5",
> >> sSrc, sTrg, ""
> >> ), vbCrLf )
> >>
> >> Function replaceAll( sSrc, aRpl )
> >> replaceAll = sSrc
> >> Dim nRpl
> >> For nRpl = 0 To UBound( aRpl, 2 )
> >> replaceAll = Replace( replaceAll, aRpl( 0, nRpl ), aRpl( 1,
> >> nRpl ) )
> >> Next
> >> End Function
> >>
> >> Function replaceAllP( sSrc, aRpl, nCount, vbComp )
> >> replaceAllP = sSrc
> >> Dim nRpl
> >> For nRpl = 0 To UBound( aRpl, 2 )
> >> replaceAllP = Replace( replaceAllP, aRpl( 0, nRpl ), aRpl( 1,
> >> nRpl ), 1, nCount,
> >> vbComp )
> >> Next
> >> End Function
> >>
> >> output:
> >>
> >> === replDemo04: Replace Demo (04) =============================
> >> sequential repl, all, honor case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei ONE TWO THREE eins zwei drei
> >>
> >> sequential repl, all, ignore case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei eins zwei drei eins zwei drei
> >>
> >> sequential repl, just one, ignore case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei ONE TWO THREE one two three
> >>
> >> nested repl, all, honor case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei ONE TWO THREE eins zwei drei
> >>
> >> nested repl, just two, ignore case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei eins zwei drei one two three
> >>
> >> looped repl, all, honor case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei ONE TWO THREE eins zwei drei
> >>
> >> looped repl, all, ignore case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei eins zwei drei eins zwei drei
> >>
> >> repl func, all, honor case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei ONE TWO THREE eins zwei drei
> >>
> >> repl func parm, just two, ignore case
> >> one two three ONE TWO THREE one two three
> >> eins zwei drei eins zwei drei one two three
> >>
> >> one repl, all, ignore case, starting at 5
> >> one two three ONE TWO THREE one two three
> >> two three eins TWO THREE eins two three
> >>
> >> === replDemo04: 0 done (00:00:00) =============================
> >>
> >> The last test case is included to show that using the start
> >> parameter should be avoided in multi-text replacements.
> >>
> >>
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Vista Logon Script Replacement VB Script
VB Script that searches a file for different text, with an append. VB Script
output .ps1 script to text file PowerShell
Multi-line text becomes a one-liner PowerShell
Multi-task in script PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46