Example of C Method for Removing Annotations Based on Regularity

  • 2021-12-13 09:03:41
  • OfStack

In this paper, an example is given to describe the method of removing annotations based on regularity in C #. Share it for your reference, as follows:


string HoverTreeClearMark(string input)
{
  input = Regex.Replace(input, @"/\*[\s\S]*?\*/", "", RegexOptions.IgnoreCase);
  input = Regex.Replace(input, @"^\s*//[\s\S]*?$", "", RegexOptions.Multiline);
  input = Regex.Replace(input, @"^\s*$\n", "", RegexOptions.Multiline);
  input = Regex.Replace(input, @"^\s*//[\s\S]*", "", RegexOptions.Multiline);
  return input;
}

This method can remove /**/ and//comments, and remove blank lines

PS: Here are two very convenient regular expression tools for your reference:

JavaScript Regular Expression Online Test Tool:
http://tools.ofstack.com/regex/javascript

Regular expression online generation tool:
http://tools.ofstack.com/regex/create_reg

For more readers interested in C # related content, please check the topics on this site: "C # Regular Expression Usage Summary", "C # Coding Operation Skills Summary", "XML File Operation Skills Summary in C #", "C # Common Control Usage Tutorial", "WinForm Control Usage Summary", "C # Data Structure and Algorithm Tutorial", "C # Object-Oriented Programming Introduction Tutorial" and "C # Programming Thread Use Skills Summary"

I hope this article is helpful to everyone's C # programming.


Related articles: