There may be a better way but will this help?
WScript.Echo Hex2String("4D006F006E00690074006F0072")
Function Hex2String()
Dim a, i, s, x, y, z
a = Split(c,"00")
For i = 0 To UBound(a)
x = Left(a(i),1)
y = Right(a(i),1)
z = 16*x+InStr("123456789ABCDEF",y)
s = s & Chr(z)
Next
Hex2String = s
End Function
> "KAKA" <KA...@discussions.microsoft.com> wrote in message
>> How to do Hex transfer to string by vb script ?
>> I want to transfer to the 4D006F006E00690074006F0072 to string, and
>> ignore the 00 . The string is Monitor
>
> There may be a better way but will this help?
>
> WScript.Echo Hex2String("4D006F006E00690074006F0072")
>
> Function Hex2String()
Function Hex2String(c)
> Dim a, i, s, x, y, z
> a = Split(c,"00")
> For i = 0 To UBound(a)
> x = Left(a(i),1)
> y = Right(a(i),1)
> z = 16*x+InStr("123456789ABCDEF",y)
> s = s & Chr(z)
> Next
> Hex2String = s
> End Function
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Thanks for catching my error.
I originally had it as:
Const c = "4D006F006E00690074006F0072"
WScript.Echo c & " = " & Hex2String()
Function Hex2String()
but changed it at the last minute.
I like your script. I ignored the '00's (as suggested by the OP), and
thus assumed that they might not be a reliable character separator.
Your script reqires the '00's to be there, which is not quite the same
as ignoring them. Now I'm beginning to think that perhaps the OP just
needs a routine to convert 16-bit Unicode to 8-bit Ansi. Doing large
scale conversions might be more efficiently accomplished using the
Microsoft.XMLDOM or ADODB.Stream objects.
Perhaps the OP will let us know.
-Paul Randall
Actually you seem to try to convert wide char key codes (UTF-16)
of little endian notation into a string.
Try this one, which does not rely on padding '00':
WScript.Echo Hex2String("4D006F006E00690074006F0072")
Function Hex2String(s)
Dim i, c
For i = 1 To Len(s) Step 4
c = c & ChrW(CLng("&H" & Mid(s,i+2,2) & Mid(s,i,2)))
Next
Hex2String = c
End Function
Note that you can rely on a pattern with double-nulls in every 3rd and
4th position as long as the string is fully UTF-8-compatible
(no keycode > 255 / FF00)
Also, as for chars from 128-255, you'd probably need some
remapping from UTF-8 to ASCII.
MfG,
Alex
MfG,
Alex
Posted as a reply to:
Re: Hex to string
KAKA schrieb:
Actually you seem to try to convert wide char key codes (UTF-16)
of little endian notation into a string.
Try this one, which does not rely on padding '00':
WScript.Echo Hex2String("4D006F006E00690074006F0072")
Function Hex2String(s)
Dim i, c
For i = 1 To Len(s) Step 4
c = c & ChrW(CLng("&H" & Mid(s,i+2,2) & Mid(s,i,2)))
Next
Hex2String = c
End Function
Note that you can rely on a pattern with double-nulls in every 3rd and
4th position as long as the string is fully UTF-8-compatible
(no keycode > 255 / FF00)
Also, as for chars from 128-255, you'd probably need some
remapping from UTF-8 to ASCII.
MfG,
Alex
MfG,
Alex
EggHeadCafe - Software Developer Portal of Choice
WCF Workflow Services Using External Data Exchange
http://www.eggheadcafe.com/tutorials/aspnet/3d49fa0d-a120-4977-842a-6dafb17b6d74/wcf-workflow-services-usi.aspx