Re: Replace function on a variable? by Pegasus
Pegasus
Mon Jul 07 06:27:53 CDT 2008
"Kasper Nordal Lund" <fake@usenet.com> wrote in message
news:uJ9Qs5A4IHA.4488@TK2MSFTNGP03.phx.gbl...
> Hi there
>
> I have a script that is getting data from a mssql server and putting it
> into a mysql serever.
>
> One of the things i get is a windows username, wich is written
> DOMAIN\username. The problem is the backslash that needs to be escaped.
>
> This can be done using replace.
>
> Replace("DOAMIN\username","\","\\") works just fine.
>
> But, the script is using a variable, so its not DOMAIN\username but
> UserName(i) wich is running in a loop.
>
> replace(UserName(i),"\","\\") gives me "Invalid use of NULL: 'replace'"
>
> replace("UserName(i)","\","\\") gives me UserName(i) everywhere.
>
> How do i use replace on a variable?
>
> /Kasper
The statement
x = Replace("DOAMIN\username","\","\\")
will set x to "DOAMIN\\username" (in spite of the spelling error).
The statement
x = replace(UserName(i),"\","\\")
will set x to the variable UserName(i), with all single backslashes replaced
by double backslashes, provided that UserName(i) exists and that the index
variable is within lbound and ubound of the array UserName. Did you test
these conditions with this simple statement?
wscript.echo "i=" & i & ", UserName(i)=" & UserName(i)
The statement
x = replace("UserName(i)","\","\\")
does exactly the same thing as your first example.