How can I remove all comments and blank lines from a C# source file. Have in mind that there could be a nested comments. Some examples:
string text = @"//not a comment"; // a comment
/* multiline
comment */ string newText = "/*not a comment*/"; // a comment
/* multiline // not a comment
/* comment */ string anotherText = "/* not a comment */ // some text here\"// not a comment"; // a comment
We can have much more complex source than those three examples above. Can some one suggest a regex pattern or other way to solve this. I've already browsed a lot a stuff over the internet and coudn't find anything that works.
Multi-line Comment ExamplesMulti-line comments have one or more lines of narrative within a set of comment delimiters. The /* delimiter marks the beginning of the comment, and the */ marks the end. You can have your comment span multiple lines and anything between those delimiters is considered a comment.
To comment out multiple lines in Python, you can prepend each line with a hash ( # ).
To remove the comments, see this answer. After that, removing empty lines is trivial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With