Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split a string without delimeter... 4

Status
Not open for further replies.

JadeKnight

IS-IT--Management
Feb 23, 2004
94
NO
I'm doing a script wich must convert a string from one format to another.

This is the string :
c9e0dbb492006a49864a94100fb34da9

This is how it should be after converted :
\c9\e0\db\b4\92\00\6a\49\86\4a\94\10\0f\b3\4d\a9

I've tried to twist my head to figure out a smart way to do it, but I'm stuck. Any help would be appreciated :)
 
[tt]dim s,u
s="c9e0dbb492006a49864a94100fb34da9"
u=""
for i=0 to len(s)-1
if i mod 2 =0 then
u=u & "\"
end if
u=u & mid(s,i+1,1)
next
wscript.echo s & vbcrlf & u
[/tt]
 
Thx, I did find a solution myself... but I think your solution was more elegant :). This is what I came up with :

Code:
Option Explicit

Dim sGUID,aGUID(),x,i

'c9e0dbb492006a49864a94100fb34da9

sGUID = "c9e0dbb492006a49864a94100fb34da9"

For i = 0 To 32
	
	ReDim Preserve aGUID(x)
	
	If i = 0 Then
		aGUID(x) = Left(sGUID, 2)
	Else	
		aGUID(x) = Mid(sGuid, i + 1, 2)
	End If

	i = i + 1
	x = x + 1
	
Next

sGUID = ""

For i = 0 To UBound(aGUID)
		sGUID = sGUID & "\" & aGUID(i)

Next

wscript.echo sGUID
 
sToMod = "c9e0dbb492006a49864a94100fb34da9"

For iCount = 1 to len(sToMod) step 2
sModed = sModed & Mid(sToMod,iCount,2) & "\"
Next

wscript.echo Left(sModed,Len(sModed)-1)

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thx MrMilson... you're way of doing it was the absolute optimal solution.
 
I don't think that MrMilson's suggestion meets the OP rules ...
My guess:
oldGUID = "c9e0dbb492006a49864a94100fb34da9"
For i = 1 To Len(oldGUID) Step 2
newGUID = newGUID & "\" & Mid(oldGUID, i, 2)
Next
WScript.Echo newGUID

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That's true PHV, I did see that and I corrected it myself. I was just after the method or principle. Not necessary a blueprint, but thx for pointing it out :)...
 
I will say up front I have learned alot from both tsuji and PHV (stars for both). I was merely trying to show another approach and with more time may have come up with PHV's suggest, maybe :)

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Or:
Code:
[blue]    sGUID = "c9e0dbb492006a49864a94100fb34da9"
    With New RegExp
        .Global = True
        .Pattern = "(..)(?:[^$])"
        sGUID = .Replace(sGUID, "$1\")
    End With[/blue]
 
I had left out the t variable worried of confusing the matter.
[tt]
set rx=new regexp
with rx
.global=true
.pattern="(..)|(.)(?=$)"
t=.replace(s,"\$1$2")
end with
wscript.echo s & vbcrlf & t
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top