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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert String to Hexadecimal 1

Status
Not open for further replies.

Noonoo

Technical User
Jul 16, 2002
35
0
0
GB
Hi people.

Can anyone tell me how I can convert a string into Hexadecimal values. e.g 'BaD' to '%42%61%44'. I've tried Hex() which seems to only work with numerics and ASCW(), which converts to decimal but can't seem to find anthing to do this.

The reason I'm trying to do this is I'm building a dynamic MailTo: link and I need to preserve capitalisation and spacing within the body.

Thanks a lot.
 
You don't have to worry about capitalization, it should stay the same. The only characters you normally have to worry about are special characters and punctuation.

VBScript has a builtin function to "url encode" strings.
Code:
<%Response.Write([b]Server.URLEncode[/b]("[URL unfurl="true"]http://www.microsoft.com"))[/URL] %>

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I don't know what op meant exactly. Try this?
[tt]
s="dim a()
redim a(len(s)-1)
for i=0 to len(s)-1
a(i)=hex(asc(mid(s,i+1,1)))
next
response.write "%" & join(a,"%")
[/tt]
- tsuji
 
Thanks for the replies. tsuji, your code does exactly what I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top