how to do unicode conversion like the IE address bar

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hi,

I would like to do something like this

Input: http://www.test.com/

to

Output: http%3A%2F%2Fwww.test.com%2F

I can't get the the conversion working using:
temp1 = Encoding.Unicode.GetBytes(strInput);
temp2 = Encoding.Convert(Encoding.Unicode, Encoding.ASCII,
temp1);
strOutput = new string(Encoding.ASCII.GetChars(temp2));

Am I missing some steps?
 
Hi,

Do you think the following is what you want?

strOutput = System.Web.HttpUtility.UrlEncode(strInput);

If you have any Qs, please reply to this post.
 
Thanks Packer, this works perfectly.

However what is the proper steps for using the Encoding
namespace? I would like to learn a flexible way to convert
string between different "encoding format".

Thanks in advance,
 
Daniel said:
Thanks Packer, this works perfectly.

However what is the proper steps for using the Encoding
namespace? I would like to learn a flexible way to convert
string between different "encoding format".

The Encoding namespace is for converting between text and binary
formats - it's nothing to do with the URL encoding you're using here
(which is text->text).

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.
 
Back
Top