473,473 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Proper (complete) Html encoding

Logan1337
38 New Member
Hello. I need to take a string in UTF-8 with extended characters (e.g trademark, curly quotes, etc) and encode it for html, with either the html named entities or xml numbered (unicode) entities.

I've tried HttpUtility.HtmlEncode(), but from what I can gather, this function is really (at least originally) only intended to prevent cross-site scripting, and therefore only encodes some characters, leaving the others unchanged.

For example, when I encode the string "<trademark><registered>" I get back "<trademark><ampersand>#174;". (sorry for the retarded representation, I ironically couldn't figure out how to represent characters in posts.) In other words, only the registered symbol is properly encoded, while the trademark symbol remains.

Is there a proper method or way to encode a string such that all extended characters are properly encoded?
Aug 28 '07 #1
1 1507
Logan1337
38 New Member
Ok guys, this is the best I've come up with, and to be quite honest I'm hardly satisfied. But it works, and right now that's what I need. If anyone has a better solution PLEASE post it. I've searched the web and found diddly.

Iterate over each character in the given string and use Convert.ToInt32(c) to get its ("hopefully" unicode) integer value. For all characters over say 127 (as I believe that's where standard ASCII ends), do this:

"&#" + intValue.ToString() + ";";

Believe it or not, it actually works. Believe me, no one was more surprised than I, especially after searching the web for a solution for more than an hour and finding nothing of any particular value.

Of course I will also apply HttpUtility.HtmlEncode() beforehand, as that will take care of the "lesser" control characters like & and <,>, quotes etc.

I've tested it with:

This is a "test" of my make-shift html encode & decode algorithm for FeedBeast™. © 2007

...and it works, so hurray.
Aug 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Ksenia Marasanova | last post by:
Hi, I have a little problem with encoding. Was hoping maybe anyone can help me to solve it. There is some amount of data in a database (PG) that must be inserted into Excel sheet and emailed....
1
by: Vlajko Knezic | last post by:
Not so sure what is going on here but is something to do with the way UTF8 is handled in Perl and/or LibXML The sctript below: - accepts a value from a form text field; - ...
59
by: Haines Brown | last post by:
I've not had a clear definition in my mind of "citation," and so have avoided it. For example, if I suggest that the reputation of the New York Times has suffered, is that a citation? I suppose...
9
by: Kerry Sanders | last post by:
I am seeing some weird behavior in the editor and with code completion. I wrote the following code just a few minutes ago: private void menuItem1_Click(object sender, System.EventArgs e) {...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
3
by: Dale Strickland-Clark | last post by:
A colleague has asked me this and I don't know the answer. Can anyone here help with this? Thanks in advance. Here is his email: I am trying to parse an HTML document using the xml.dom.minidom...
14
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html...
1
by: Ralf Ziller | last post by:
I have a GridView which I want to send via email. I have overriden VerifyRenderingInServerForm to allow this. But if I call RenderControl to write the html markup in a memory stream I only get...
0
drhowarddrfine
by: drhowarddrfine | last post by:
The Doctype or DTD Many coders get confused by all the talk of doctypes and how they affect browsers and the display of their web pages. This article will get right to the point about doctypes...
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
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: 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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.