I use a object that returns a list of computernames to perform a function.
Since we have done a good job with our computer naming conventions I am
using this object but want to replace just part of the computername to query
the other device on network.


For example,

I get a list of machines named:

DC1RES000101
DC2RES000102
DC3RES000103

As I get each machine using a For Each statement...I need to replace the
'RES' with a 'SCS'

DC1SCS000101
DC2SCS000102
DC3SCS000103


How can I do a replace of the three letters in middle of computerName.

Re: replace part of a string by Ayush

Ayush
Mon Jan 29 09:42:10 CST 2007

Replied to [Big D]s message :
> I use a object that returns a list of computernames to perform a function.
> Since we have done a good job with our computer naming conventions I am
> using this object but want to replace just part of the computername to query
> the other device on network.
>
>
> For example,
>
> I get a list of machines named:
>
> DC1RES000101
> DC2RES000102
> DC3RES000103
>
> As I get each machine using a For Each statement...I need to replace the
> 'RES' with a 'SCS'
>
> DC1SCS000101
> DC2SCS000102
> DC3SCS000103
>
>
> How can I do a replace of the three letters in middle of computerName.
>
>

Use Replace method :
Replace(string,replaceWord,replaceWith)

for example:
replace(computerNames,"RES","SCS")


OR Use RegExp.Replace :

set regXp = New RegExp
regXp.Pattern = "\w{3}RES\w{6}"


AND put the folowing in loop :
regXp.Replace(computerName,"SCS")

--
â?? Ayush
-------------
Search - www.Google.com | Wikipedia - http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------

Re: replace part of a string by Anthony

Anthony
Mon Jan 29 10:26:36 CST 2007


"Ayush" <"ayushmaan.j[aatt]gmail.com"> wrote in message
news:eNQrsw7QHHA.5032@TK2MSFTNGP03.phx.gbl...
> Replied to [Big D]s message :
> > I use a object that returns a list of computernames to perform a
function.
> > Since we have done a good job with our computer naming conventions I am
> > using this object but want to replace just part of the computername to
query
> > the other device on network.
> >
> >
> > For example,
> >
> > I get a list of machines named:
> >
> > DC1RES000101
> > DC2RES000102
> > DC3RES000103
> >
> > As I get each machine using a For Each statement...I need to replace the
> > 'RES' with a 'SCS'
> >
> > DC1SCS000101
> > DC2SCS000102
> > DC3SCS000103
> >
> >
> > How can I do a replace of the three letters in middle of computerName.
> >
> >
>
> Use Replace method :
> Replace(string,replaceWord,replaceWith)
>
> for example:
> replace(computerNames,"RES","SCS")
>

That'll work well if there are no other occurances of RES that don't need
replacing.

>
> OR Use RegExp.Replace :
>
> set regXp = New RegExp
> regXp.Pattern = "\w{3}RES\w{6}"
>
>
> AND put the folowing in loop :
> regXp.Replace(computerName,"SCS")
>

A loop is unnecessary howevet it will replace the whole computer name not
just the RES in the name.

set rgx = New RegExp
rgx.Pattern = "(\w{3})RES(?=\w{6})"
rgx.Global = True

computerNames = rgx.Replace(computerNames, "$1SCS")



> --
> ? Ayush
> -------------
> Search - www.Google.com | Wikipedia - http://en.wikipedia.org
> Snip your long urls - http://snipurl.com/
> -------------



Re: replace part of a string by Ayush

Ayush
Mon Jan 29 11:37:11 CST 2007

Replied to [Anthony Jones]s message :
>> AND put the folowing in loop :
>> regXp.Replace(computerName,"SCS")
>>
>
> A loop is unnecessary

He said he is using For Each..


> howevet it will replace the whole computer name not
> just the RES in the name.


Oh.. forgot about that..


> set rgx = New RegExp
> rgx.Pattern = "(\w{3})RES(?=\w{6})"
> rgx.Global = True
>
> computerNames = rgx.Replace(computerNames, "$1SCS")


--
â?? Ayush
-------------
Search - www.Google.com | Wikipedia - http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------

Re: replace part of a string by Anthony

Anthony
Mon Jan 29 16:32:39 CST 2007


"Ayush" <"ayushmaan.j[aatt]gmail.com"> wrote in message
news:O0GhEx8QHHA.3500@TK2MSFTNGP05.phx.gbl...
> Replied to [Anthony Jones]s message :
> >> AND put the folowing in loop :
> >> regXp.Replace(computerName,"SCS")
> >>
> >
> > A loop is unnecessary
>
> He said he is using For Each..
>
>

He did. I stand corrected. ;)




Re: replace part of a string by Big

Big
Tue Jan 30 20:18:23 CST 2007

Thanks for your help guys. I implemented and is working great.
"Anthony Jones" <Ant@yadayadayada.com> wrote in message
news:%234PhjV$QHHA.1180@TK2MSFTNGP05.phx.gbl...
>
> "Ayush" <"ayushmaan.j[aatt]gmail.com"> wrote in message
> news:O0GhEx8QHHA.3500@TK2MSFTNGP05.phx.gbl...
>> Replied to [Anthony Jones]s message :
>> >> AND put the folowing in loop :
>> >> regXp.Replace(computerName,"SCS")
>> >>
>> >
>> > A loop is unnecessary
>>
>> He said he is using For Each..
>>
>>
>
> He did. I stand corrected. ;)
>
>
>