473,466 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with £ being posted back to site

Hi

I'm having a bit of difficulty with some text encoding, the problem is
that i have set up all posts so that "ISO-8859-1" is used so that when
a user adds the pound symbol "£" in a text area field then character
is encoded to "&#163" and if the user includes "&" in the text area
then the character is encoded to "&", this is nessasary so that
users can use the "£" symbol. The problem is that text area field has
a character length validatin check on it and if the user includes the
"£" or "&" characters in the text then the characters are counted as 5
and 4 characters respectiveley instead of 1. I have tried to convert
the string from the text area to "ISO-8859-1" so that "&#163" is
changed to "£" using the code below but this does not seem to work.

String aString = jobDescriptionTextArea.Value;

Encoding latinEuropeanEncoding =
System.Text.Encoding.GetEncoding("iso-8859-1");
Encoding uniCode = Encoding.Unicode;

byte[] latinBytes = latinEuropeanEncoding.GetBytes(aString);

byte[] unicodeBytes = Encoding.Convert(latinEuropeanEncoding,
uniCode, latinBytes);

char[] unicodeCharArray = new char[uniCode.GetCharCount(unicodeBytes,
0, unicodeBytes.Length)];

uniCode.GetChars(unicodeBytes, 0, unicodeBytes.Length,
unicodeCharArray, 0);

String outputString = new String(unicodeCharArray);

Response.Write("converted string >" + outputString + "<<br>");

Any suggestions?

Cheers

Tony

Jul 24 '06 #1
1 1265
Thus wrote te******@googlemail.com,
Hi

I'm having a bit of difficulty with some text encoding, the problem is
that i have set up all posts so that "ISO-8859-1" is used so that when
a user adds the pound symbol "£" in a text area field then character
is encoded to "&#163" and if the user includes "&" in the text area
then the character is encoded to "&amp;",
This is actually HTML encoding of Unicode characters and has nothing to do
with ISO-8859-1.
this is nessasary so that
users can use the "£" symbol. The problem is that text area field has
a character length validatin check on it and if the user includes the
"£" or "&" characters in the text then the characters are counted as 5
and 4 characters respectiveley instead of 1. I have tried to convert
the string from the text area to "ISO-8859-1" so that "&#163" is
changed to "£" using the code below but this does not seem to work.
How is the validation check implemented? In JavaScript on the client? ASP.NET
knows that "&#163" is one character, so a CustomValidator shouldn't have
this problem. Also note that you can encode the pound sign natively. You
don't have to use a HTML character entity.

Your code is more or less a NOOP if all characters jobDescriptionTextArea.Value
can be represented in Latin 1 -- it just shuttles the characters back and
forth between UTF-16 and Latin 1 representaton.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jul 29 '06 #2

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

Similar topics

2
by: Darrell Blake | last post by:
I'm trying to use sessions to allow people to log into my site. The problem is that sometimes it works and sometimes it doesn't! As far as I'm aware my script is fine (hence why it works sometimes)...
7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
5
by: fripper | last post by:
I posted this problem a couple of days ago but felt I might have better luck re-stating the problem. Apparently I messed up IIS (v. 5) somehow because I am suddenly unable to load web forms! A...
4
by: DotNetJunkies User | last post by:
Hello everyone: Ok here is a very weird problem I am having and I hope that some of you can share some thoughts with me on this. First of all, let me start by listing what I have: 1.-...
13
by: chuckdfoster | last post by:
I am having a problem with my ASP.NET application and using Windows Authentication. It works until I take the "Everyone" group away from the permissions. Then it won't let anyone in, including...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
9
by: Ron | last post by:
New discovery. If I take a perfectly good database, and "compact/repair" on it with Access 2000 (seems to be at multiple sites--I've tried it with my system here, at another office on an...
6
by: mcl | last post by:
I have a domain name which is set up for web forwarding with a frame. I have a link on one of the site's pages to an external site. When I select the link the external site is displayed correctly...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
1
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...
0
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...
0
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,...
0
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...
0
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...

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.