tags:

views:

656

answers:

3

Hello,

I have a string with &#xA in it the regex:

  • string value = Regex.Replace(textNode.Value, @"\s+", " ");

  • value = value.Replace(" ", "");

  • value = Regex.Replace(value, @"\&#xA", "");

  • value = value.Replace("\n", "");

didn't remove it.

How do I go about removing &#xA?

Note: It did function as a newline when added to a textbox.

Thanks.

+1  A: 

Regex is not necessary for simple string manipulation in .Net. System.String has a Replace method.

VB

myString = myString.Replace("&#xA", "")

C#

myString = myString.Replace("&#xA", "");

However, is &#xA is not an actual string, but a byte, (The way 1 is a number, but "1" is a string) the code would be different. But as the question was asked, the above would be the answer.

Edit - added after your comment

Based on the fact that your code sample contained "textNode.Value" I'm gussing you're parsing XML. If so, your question has already been asked and answered here:

http://stackoverflow.com/questions/848841/c-xslt-transform-adding-xa-and-xd-to-the-output

David Stratton
While this looks straight forward, it didn't work, Still has in string!
XmlQuestioner
This shows up in VS's Text Visualiser, but not the XML Visualiser
XmlQuestioner
Need a non-xslt answer
XmlQuestioner
A: 

Escape the ampersand in your regex

string s = "hello &#xA there";

Console.WriteLine(Regex.Replace(s, @"\&#xA", ""));
//or more simply:
Console.WriteLine(s.Replace("&#xA", ""));
Jeffrey Knight
is only visable via VS's Text, XML or HTML variable view, in Text mode, in XML is not shown!
XmlQuestioner
A: 

&#xA is a new line character, if I recall correctly. If David Stratton's edited answer didn't do it for you, try this:

myString = myString.Replace("\n", "");
Cam Soper