473,544 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URL Decoding Issue --- HELP!

I have a URL Decoding issue.

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

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

This is what I tried:

string encodedText = "123+H%F6gbergs gatan+st";

string decodedText =
System.Web.Http Utility.UrlDeco de(encodedText, System.Text.Enc oding.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%F6gbergs gatan+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.Http Utility.UrlEnco de(origText,Sys tem.Text.Encodi ng.UTF8);

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

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

-Ron
Nov 19 '05 #1
3 2269
UTF7

string decodedText =
System.Web.Http Utility.UrlDeco de(encodedText, System.Text.Enc oding.UTF7);

Gabriel Lozano-Morán

"Ron Clabo" <cl*********@do ntspamme.adelph ia.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I have a URL Decoding issue.

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

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

This is what I tried:

string encodedText = "123+H%F6gbergs gatan+st";

string decodedText =
System.Web.Http Utility.UrlDeco de(encodedText, System.Text.Enc oding.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%F6gbergs gatan+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.Http Utility.UrlEnco de(origText,Sys tem.Text.Encodi ng.UTF8);

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

I have two questions! How do I get .net to encode it as
"123+H%F6gbergs gatan+st" ? and also when I have a string
"123+H%F6gbergs gatan+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%F6gbergs gatan+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%2bAP Y-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%F6gbergs gatan+st". Any thoughts?

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

string decodedText =
System.Web.Http Utility.UrlDeco de(encodedText, System.Text.Enc oding.UTF7);

Gabriel Lozano-Morán

"Ron Clabo" <cl*********@do ntspamme.adelph ia.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I have a URL Decoding issue.

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

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

This is what I tried:

string encodedText = "123+H%F6gbergs gatan+st";

string decodedText =
System.Web.Http Utility.UrlDeco de(encodedText, System.Text.Enc oding.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%F6gbergs gatan+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.Http Utility.UrlEnco de(origText,Sys tem.Text.Encodi ng.UTF8);

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

I have two questions! How do I get .net to encode it as
"123+H%F6gbergs gatan+st" ? and also when I have a string
"123+H%F6gbergs gatan+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%F6gbergs gatan+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%F6gbergs gatan+st" ? and also when I have a string
"123+H%F6gbergs gatan+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.Enc oding, so you
have to create one using
// by IANA name
Encoding enc = Encoding.GetEnc oding("ISO-8859-1");
or
// by Windows' internal character set code
Encoding enc = Encoding.GetEnc oding(28591);

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

To encode a string, use HttpUtility.Url Encode().

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3959
by: steve | last post by:
Hi, I am opening a stream that is UTF encoded. I use fgetc to read the stream- which is binary safe. I add every character read to a string. But when I look at the stream, I see some characters with a bunch of "?" question markets, and then utf8_decode has no effect on it either. How do you go about decoding utf. Does adding the...
40
3164
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. However when you retrieve these values into a dataset and ToString() them
0
2753
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the idea that costs nothing and it is inheritently built into the Framework. So here is the solution... When you use the WebRequest and WebResponse...
0
1997
by: R L Vandaveer | last post by:
I am having an interesting and rather frustrating issue with the encoding/decoding of parameters with the ASP.NET runtime. What I am doing isn't exactly revolutionary so hopefully someone has an answer for this. I have a page that accepts a number of parameters. Those parameters may sometimes include URL reserved characters like spaces and...
5
6351
by: Peter Jansson | last post by:
Hello group, The following code is an attempt to perform URL-decoding of URL-encoded string. Note that std::istringstream is used within the switch, within the loop. Three main issues have been raised about the code; 1. If characters after '%' do not represent hexademical number, then uninitialized value variable 'hexint' used - this is...
25
3361
by: marcin.rzeznicki | last post by:
Hello everyone I've got a little problem with choosing the best decoding strategy for some nasty problem. I have to deal with very large files wich contain text encoded with various encodings. Their length makes loading contents of file into memory in single run inappropriate. I solved this problem by implementing memory mapping using...
2
7908
by: pmz | last post by:
Dear Group, I've got a problem with decoding e-mail message subject, which has been read within usage of Pear_Mail_Mime library. There are some elements unwelcome in my subject string, such as: =?ISO-8859-2?Q?My subject. Especially when subject contains polish characters, i.e.:
5
2834
by: =?Utf-8?B?Um9iZXJ0?= | last post by:
Hello all, I have an XmlException being thrown trying to use XslCompiledTransform while using the google api. My suspicion is there is some html decoding happening that I want to prevent... something like this being changed into this
0
1805
by: Michele | last post by:
Hi there, I'm using a python script in conjunction with a JPype, to run java classes. So, here's the code: from jpype import * import os import random import math import sys
0
7417
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7361
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7601
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7701
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5901
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4908
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
654
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.