472,121 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

URL Decoding Issue --- HELP!

I have a URL Decoding issue.

The text that needs to be decoded is: "123+H%F6gbergsgatan+st"

The decoded version should equate to: "123 Högbergsgatan st"

This is what I tried:

string encodedText = "123+H%F6gbergsgatan+st";

string decodedText =
System.Web.HttpUtility.UrlDecode(encodedText,Syste m.Text.Encoding.UTF8);

However, it does not work! decodedText ends up being "123 Hgbergsgatan st"
i.e. the ö is omitted.

So to verify that the original text was encoded properly I referenced this
website: http://www.w3schools.com/html/html_ref_urlencode.asp It has a
place where you can paste in a string and click a button to see it's URL
encoded version. Sure enough, the correct url encoding for "123
Högbergsgatan st" is "123+H%F6gbergsgatan+st". As an aside, I also tried
pasting the text into a google search box to see how it got encoded in the
google url. Same encoding. So if it's incoded right, why can't I decode it
in .net?

Still frustrated, I tried using .net to encode the source string (i.e. "123
Högbergsgatan st" to see how it encoded it.

string origText = "123 Högbergsgatan st ";

string encodedText =
System.Web.HttpUtility.UrlEncode(origText,System.T ext.Encoding.UTF8);

And low and behold it encoded it different. It encoded it as
"123+H%c3%b6gbergsgatan+st"!!!

I have two questions! How do I get .net to encode it as
"123+H%F6gbergsgatan+st" ? and also when I have a string
"123+H%F6gbergsgatan+st" how do it get .net to decode it as "123
Högbergsgatan st" ?

-Ron
Nov 19 '05 #1
3 2177
UTF7

string decodedText =
System.Web.HttpUtility.UrlDecode(encodedText,Syste m.Text.Encoding.UTF7);

Gabriel Lozano-Morán

"Ron Clabo" <cl*********@dontspamme.adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I have a URL Decoding issue.

The text that needs to be decoded is: "123+H%F6gbergsgatan+st"

The decoded version should equate to: "123 Högbergsgatan st"

This is what I tried:

string encodedText = "123+H%F6gbergsgatan+st";

string decodedText =
System.Web.HttpUtility.UrlDecode(encodedText,Syste m.Text.Encoding.UTF8);

However, it does not work! decodedText ends up being "123 Hgbergsgatan
st"
i.e. the ö is omitted.

So to verify that the original text was encoded properly I referenced this
website: http://www.w3schools.com/html/html_ref_urlencode.asp It has a
place where you can paste in a string and click a button to see it's URL
encoded version. Sure enough, the correct url encoding for "123
Högbergsgatan st" is "123+H%F6gbergsgatan+st". As an aside, I also tried
pasting the text into a google search box to see how it got encoded in the
google url. Same encoding. So if it's incoded right, why can't I decode
it
in .net?

Still frustrated, I tried using .net to encode the source string (i.e.
"123
Högbergsgatan st" to see how it encoded it.

string origText = "123 Högbergsgatan st ";

string encodedText =
System.Web.HttpUtility.UrlEncode(origText,System.T ext.Encoding.UTF8);

And low and behold it encoded it different. It encoded it as
"123+H%c3%b6gbergsgatan+st"!!!

I have two questions! How do I get .net to encode it as
"123+H%F6gbergsgatan+st" ? and also when I have a string
"123+H%F6gbergsgatan+st" how do it get .net to decode it as "123
Högbergsgatan st" ?

-Ron

Nov 19 '05 #2
Gabriel - thanks for the reply and the great tip. Using UTF7 does indeed
allow me to decode "123+H%F6gbergsgatan+st" into "123 Högbergsgatan st" !
One problem solved. But unfortunately the reverse is not true. When I try
to use UTF7 to encode "123 Högbergsgatan st" it returns
"123+H%2bAPY-gbergsgatan+st". Ugg. Interestingly using UTF7 to decode this
result does get me back to the original string. Odd that two different
encodings would decode back to the original with UTF7 - I don't get why.

So I still need help on how I encode "123 Högbergsgatan st" into
"123+H%F6gbergsgatan+st". Any thoughts?

-Ron
"Gabriel Lozano-Morán" <ga************@no-spam.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
UTF7

string decodedText =
System.Web.HttpUtility.UrlDecode(encodedText,Syste m.Text.Encoding.UTF7);

Gabriel Lozano-Morán

"Ron Clabo" <cl*********@dontspamme.adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I have a URL Decoding issue.

The text that needs to be decoded is: "123+H%F6gbergsgatan+st"

The decoded version should equate to: "123 Högbergsgatan st"

This is what I tried:

string encodedText = "123+H%F6gbergsgatan+st";

string decodedText =
System.Web.HttpUtility.UrlDecode(encodedText,Syste m.Text.Encoding.UTF8);

However, it does not work! decodedText ends up being "123 Hgbergsgatan
st"
i.e. the ö is omitted.

So to verify that the original text was encoded properly I referenced this website: http://www.w3schools.com/html/html_ref_urlencode.asp It has a place where you can paste in a string and click a button to see it's URL
encoded version. Sure enough, the correct url encoding for "123
Högbergsgatan st" is "123+H%F6gbergsgatan+st". As an aside, I also tried pasting the text into a google search box to see how it got encoded in the google url. Same encoding. So if it's incoded right, why can't I decode it
in .net?

Still frustrated, I tried using .net to encode the source string (i.e.
"123
Högbergsgatan st" to see how it encoded it.

string origText = "123 Högbergsgatan st ";

string encodedText =
System.Web.HttpUtility.UrlEncode(origText,System.T ext.Encoding.UTF8);

And low and behold it encoded it different. It encoded it as
"123+H%c3%b6gbergsgatan+st"!!!

I have two questions! How do I get .net to encode it as
"123+H%F6gbergsgatan+st" ? and also when I have a string
"123+H%F6gbergsgatan+st" how do it get .net to decode it as "123
Högbergsgatan st" ?

-Ron


Nov 19 '05 #3
Ron Clabo wrote:
I have a URL Decoding issue.

The text that needs to be decoded is: "123+H%F6gbergsgatan+st"

The decoded version should equate to: "123 Högbergsgatan st"
[...]
I have two questions! How do I get .net to encode it as
"123+H%F6gbergsgatan+st" ? and also when I have a string
"123+H%F6gbergsgatan+st" how do it get .net to decode it as "123
Högbergsgatan st" ?


I have no freakin' clue why the other poster wants to use UTF-7 here.
This is ISO-8859-1, which is still widely used for Western European or
North American language web sites.

There's no default ISO-8859-1 instance in System.Text.Encoding, so you
have to create one using
// by IANA name
Encoding enc = Encoding.GetEncoding("ISO-8859-1");
or
// by Windows' internal character set code
Encoding enc = Encoding.GetEncoding(28591);

And since your string is URL encoded as well, you have to use
string str = System.Web.HttpUtility.UrlDecode(encodedStr, enc);

To encode a string, use HttpUtility.UrlEncode().

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by steve | last post: by
reply views Thread by R L Vandaveer | last post: by
5 posts views Thread by Peter Jansson | last post: by
25 posts views Thread by marcin.rzeznicki | last post: by
2 posts views Thread by pmz | last post: by
5 posts views Thread by =?Utf-8?B?Um9iZXJ0?= | last post: by
reply views Thread by Michele | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.