Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hex to string

1,609 views
Skip to first unread message

KAKA

unread,
Dec 11, 2007, 8:28:02 PM12/11/07
to
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
Thanks.

McKirahan

unread,
Dec 11, 2007, 9:28:51 PM12/11/07
to
"KAKA" <KA...@discussions.microsoft.com> wrote in message
news:8447B304-3580-4E58...@microsoft.com...

> 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()
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.

unread,
Dec 12, 2007, 3:37:52 AM12/12/07
to
McKirahan wrote on 12 dec 2007 in microsoft.public.scripting.vbscript:

> "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)

McKirahan

unread,
Dec 12, 2007, 8:59:51 AM12/12/07
to
"Evertjan." <exjxw.ha...@interxnl.net> wrote in message
news:Xns9A0461F8...@194.109.133.242...

> McKirahan wrote on 12 dec 2007 in microsoft.public.scripting.vbscript:
>
> > "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)

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.


Paul Randall

unread,
Dec 12, 2007, 1:07:53 PM12/12/07
to

"McKirahan" <Ne...@McKirahan.com> wrote in message
news:MP2dnXWzX6iFdMLa...@comcast.com...

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


Alexander Mueller

unread,
Dec 12, 2007, 8:09:16 PM12/12/07
to
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

fredsens

unread,
Sep 15, 2009, 2:28:56 AM9/15/09
to
You are required to be a member to post replies. After logging in or becoming a member, you will be redirected back to this page.

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

0 new messages