Posted By

jasonseney on 10/02/09


Tagged

html xml csharp


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

gzjian
vali29
khouser


C# Strip XML/HTML from string


 / Published in: C#
 

  1. public static string StripXML(string source)
  2. {
  3. char[] buffer = new char[source.Length];
  4. int bufferIndex = 0;
  5. bool inside = false;
  6.  
  7. for (int i = 0; i < source.Length; i++)
  8. {
  9. char let = source[i];
  10. if (let == '<')
  11. {
  12. inside = true;
  13. continue;
  14. }
  15. if (let == '>')
  16. {
  17. inside = false;
  18. continue;
  19. }
  20. if (!inside)
  21. {
  22. buffer[bufferIndex] = let;
  23. bufferIndex++;
  24. }
  25. }
  26. return new string(buffer, 0, bufferIndex);
  27. }

Report this snippet  

You need to login to post a comment.