C# Strip XML/HTML from string


/ Published in: C#
Save to your folder(s)

[Credit - Sam Allen, Dot Net Perls](http://dotnetperls.com/remove-html-tags)


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.