473,705 Members | 5,438 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 2283
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
3969
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 characters to the
40
3231
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
2761
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 classes to obtain graphics from a web site, these classes have built-in decoding for JPEG 2000 files....
0
2018
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 ampersands. I use a combination of HTML and URL encoding to build links to this page and...
5
6363
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 undefined behavior. 2. This code is very inefficient - to many mallocs/string
25
3403
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 P/Invoke and I load contents of file in chunks. Since files' contents are in different encodings what I...
2
7930
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
2856
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
1820
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
8689
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5933
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4439
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2081
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.