Tom Lavedas replied to sudhi_shrivatsa
13-Nov-09 05:41 PM

OK, so multiple zeros ARE a problem. It turns out the solution was a
lot easier than I first imagined or I might have addressed before.
Try this, instead ...
sHostName =3D "file00123"
nPos =3D RegExpPos("\d", sHostName)
if nPos > 0 and nPos <=3D Len(sHostName) then
sUserName =3D "user" & Mid(sHostName, nPos)
wsh.echo sHostName, "=3D>", sUserName
else
wsh.echo "Unable to parse Hostname", sHostName
end if
Function RegExpPos(patrn, strng)
Dim regEx, Match, Matches, RetPos ' Declare variables.
Set regEx =3D New RegExp ' Create regular expression.
regEx.Pattern =3D patrn ' Set pattern.
regEx.IgnoreCase =3D True ' Set case insensitivity.
regEx.Global =3D false ' Set non-global applicability.
Set Matches =3D regEx.Execute(strng) ' Execute search.
if Matches.count > 0 then
RetPos =3D Matches(0).FirstIndex + 1
if Matches(0).Value =3D "0" then RetPos =3D RetPos + 1
else
RetPos =3D 0
end if
RegExpPos =3D RetPos
End Function
BTW, the \d pattern is shorthand for [0-9] - match all digits.
_____________________
Tom Lavedas