1

After extracting a piece of text in my application, I might end up with a string like this:

"More kitchen supplies for the people" 

Which in plain text would be:

"More kitchen supplies for the people" 

Is there a component/method in .NET I can use to "process" the string into its plain text equivalent?

I'm able to assume regular ascii text in general, no odd unicode or strange alphabets. It just seems that normal signs like ', ", | etc. are provided as character codes.

EDIT: I think I should note that this is about .NET for Windows desktop development. Appearantly there are methods to do this for ASP.NET only, and I didn't realize that simple operations like this could be limited to specific .NET platforms.

2
  • @xOn: I appreciate your response, however due to my own ignorance it seems it doesn't apply to my environment. Please see the update to the question. Commented Oct 4, 2009 at 13:27
  • you can use System.Web assemblies in any .NET desktop application. Commented Oct 5, 2009 at 2:43

2 Answers 2

8

The System.Web.HttpUtility.HtmlDecode method can handle this:

(powershell v2 example)

ps> add-type -an system.web ps> [system.web.httputility]::HtmlDecode(""") " ps> 

Hope this helps,

-Oisin

Sign up to request clarification or add additional context in comments.

8 Comments

I'm not sure why, but "HttpUtility" is not present in my System.Web namespace. Looking at the online help, it should be part of the .NET library, but the example code only shows examples for ASP.NET.
System.Web.HttpUtility is a class in the .NET 2.0 System.Web assembly. I'm pretty sure it's in 1.1 too. What version are you usuing?
I'm using .NET 3.5 SP1. The System.Web assembly is version 2.0 according to the references dialog. I have only three classes in System.Web: AspNetHostingPermission, AspNetHostingPermissionAttribute and AspNetHostingPermissionLevel. Despite intellisense I tried to instantiate HttpUtility, but I get: error CS0234: The type or namespace name 'HttpUtility' does not exist in the namespace 'System.Web'.
You don't instantantiate it - it's a static class. System.Web.HttpUtility.HtmlDecode("my text ...")
If you only have 3 classes in system.web, something is very very wrong.
|
0

If you know the codes are ASCII you can use the following to convert each little &x22 number.

public char Convert(string data) { data = data.SubString(1); // Lose the & var num = Int32.Parse(data, NumberStyles.Hex | NumberStyles.AllowHexSpecifier); var chars = Encoding.ASCII.GetChars(new byte[] { (byte)num }); return chars[0]; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.