Forum Moderators: open

Message Too Old, No Replies

Replace multiple special characters within a string

         

supermanjace

3:48 am on Oct 15, 2008 (gmt 0)

10+ Year Member



I am trying to match a string that is the innerHTML of a link I click to it's counterpart in an XML doc.

The innerHTML string from my html doc is something along the lines of :

<span class="brand">Aventinus</span> <span class="beer">Eisbock</span>

Obviously, this is not a great string to use as my comparison, as it is rife with special characters. Is there a way to take this string and convert it to something a little less special, a string that has no special characters so I can make that non-special string also be my comparison line in my XML doc.

I had created: &#60;span class&#61;&#34;brand&#34;&#62;Aventinus&#60;&#47;span&#62; &#60;span class&#61;&#34;beer&#34;&#62;Eisbock&#60;&#47;span&#62;

but then I will have to make this long ass string while escaping each special character on the XML doc, where if I could just get rid of them on the HTML side's return string, that would be swell.

Thanks in advance...

adaptor40

6:28 am on Oct 15, 2008 (gmt 0)

10+ Year Member



maybe u can use a regular exp to get rid of special chars
string ret = System.Text.RegularExpressions.Regex.Replace(strVal, @"[^\w,\.@-]", "");

i use this in c#...maybe u can adapt the regex