Re: Needing replacing a backslash by a comma by ekkehard
ekkehard
Mon May 12 17:36:56 CDT 2008
ekkehard.horner schrieb:
> Blosjos schrieb:
>> Hello,
>>
>> I just need to know how to find the third backslash in a string like
>> this:
>>
>> \\192.168.1.2\SYSVOL
>>
>> It is like it was really \\anything\anything
>>
>> and then replace it by a comma so that the string can be like:
>>
>> \\192.168.1.2,SYSVOL
>>
>> I have been trying with regular expressions but unsuccessfully.
>>
>> Any ideas?
>>
>> Thank you!
>>
>>
> You could use code like this:
>
> Dim aTests : aTests = Array( _
> "\\192.168.1.2\SYSVOL" _
> , "\\192.168.1.2\SYSVOL\x" _
> , "\x\192.168.1.2\SYSVOL" _
> )
> Dim sTest
> For Each sTest in aTests
> ' Replace(expression, find, replacewith[, start[, count[, compare]]])
> WScript.Echo sTest, "=>", Replace( sTest, "\", ",", 3, 1,
> vbBinaryCompare )
> Next
>
> output:
>
> === replBackslash: replace third backslash ====
> \\192.168.1.2\SYSVOL => 192.168.1.2,SYSVOL
> \\192.168.1.2\SYSVOL\x => 192.168.1.2,SYSVOL\x
> \x\192.168.1.2\SYSVOL => ,192.168.1.2\SYSVOL
> === replBackslash: 0 done (00:00:00) ==========
>
> to check if using Replace is an easy/efficient way to solve your
> problem.
Looks like this way wasn't easy enough for me! To get the desired
output:
\\192.168.1.2\SYSVOL => \\192.168.1.2,SYSVOL
the Replace call should be:
WScript.Echo sTest, "=>", "\\" & Replace( sTest, "\", ",", 3, 1, vbBinaryCompare )