Home All Groups Group Topic Archive Search About

Using the replace command, please help

Author
10 Mar 2006 11:13 PM
Chris
In the following script I use the replace command to change R to 1 in a
string variable so that replacing Rdgpc-test = 1dgpc-test,  and this
works fine


Dim strcomputer, strcomputer1
Strcomputer = "rdgpc-test"
Strcomputer1 = (Replace(strcomputer,"R", "1"))
msgbox strcomputer1


However If strcomputer = "rdgpc-Rdgtest" then the result =
1dgpc-1dgtest

Is their anyway I can replace just the first instance, or just the
first character??

I have not been able to find anyway to do this and yet it seems like
such a simple task.

Any help would be greatly appreciated.

Thanks in advanced

Chris

Author
10 Mar 2006 11:18 PM
Bob Butler
Show quote Hide quote
"Chris" <chris_simon_***@yahoo.com> wrote in message
news:1142032422.952149.117600@e56g2000cwe.googlegroups.com
> In the following script I use the replace command to change R to 1 in
> a string variable so that replacing Rdgpc-test = 1dgpc-test,  and this
> works fine
>
>
> Dim strcomputer, strcomputer1
> Strcomputer = "rdgpc-test"
> Strcomputer1 = (Replace(strcomputer,"R", "1"))
> msgbox strcomputer1
>
>
> However If strcomputer = "rdgpc-Rdgtest" then the result =
> 1dgpc-1dgtest
>
> Is their anyway I can replace just the first instance, or just the
> first character??
>
> I have not been able to find anyway to do this and yet it seems like
> such a simple task.

How did you search for a way to do it?  Did you try looking at the help or
the intellisense for Replace?

replace(expression,find,replace,[start],[count],[method])

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
10 Mar 2006 11:21 PM
Ken Halter
Show quote Hide quote
"Chris" <chris_simon_***@yahoo.com> wrote in message
news:1142032422.952149.117600@e56g2000cwe.googlegroups.com...
> In the following script I use the replace command to change R to 1 in a
> string variable so that replacing Rdgpc-test = 1dgpc-test,  and this
> works fine
>
>
> Dim strcomputer, strcomputer1
> Strcomputer = "rdgpc-test"
> Strcomputer1 = (Replace(strcomputer,"R", "1"))
> msgbox strcomputer1
>
>
> However If strcomputer = "rdgpc-Rdgtest" then the result =
> 1dgpc-1dgtest
>
> Is their anyway I can replace just the first instance, or just the
> first character??
>
> I have not been able to find anyway to do this and yet it seems like
> such a simple task.
>
> Any help would be greatly appreciated.
>
> Thanks in advanced
>
> Chris

In VB6, it would be.....
'=======
Private Sub Form_Load()
   Dim sTest As String
   sTest = "rdgpc-Rdgtest"
   Debug.Print Replace$(sTest, "r", "1", 1, 1) '<-shows 1dgpc-Rdgtest
End Sub
'=======

Not sure about script

Another way... just chop off the first character.
'=======
Private Sub Form_Load()
   Dim sTest As String
   sTest = "rdgpc-Rdgtest"
   sTest = "1" & Mid$(sTest, 2)
   Debug.Print sTest 'shows 1dgpc-Rdgtest
End Sub
'=======



--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Author
13 Mar 2006 2:03 PM
Chris
Thanks for the help Ken, that was so much easier then using the replace
command.  Here is how I did the code for vbscript, very similar.



Dim strcomputer, strcomputer1
Strcomputer = "rdgpc-test"
Strcomputer1 = "1" & mid(strcomputer, 2)
msgbox strcomputer1

Thanks again, I really appreciate the help


Chris
Author
11 Mar 2006 10:07 AM
Mike Williams
"Chris" <chris_simon_***@yahoo.com> wrote in message
news:1142032422.952149.117600@e56g2000cwe.googlegroups.com...

> However If strcomputer = "rdgpc-Rdgtest" then the result
> 1dgpc-1dgtest Is their anyway I can replace just the first
> instance, or just the first character??

The best way would be to type the word Replace into your code and hit the F1
key ;-)

Mike