Created
July 23, 2014 20:50
-
-
Save tecnocrata/e69abbff5295bdf19849 to your computer and use it in GitHub Desktop.
Comment / Uncomment C# Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private string CommentSelection(string selected) | |
| { | |
| var result = string.Empty; | |
| try | |
| { | |
| var lineMatches = Regex.Matches(selected, ".*", RegexOptions.Multiline); | |
| foreach (var lineMatch in lineMatches) | |
| { | |
| if (string.IsNullOrEmpty(lineMatch.ToString())) continue; | |
| result = result + @"//" + lineMatch.ToString(); | |
| } | |
| } | |
| catch (ArgumentException ex) | |
| { | |
| // Syntax error in the regular expression | |
| } | |
| return result; | |
| } | |
| private string UnCommentSelection(string selected) | |
| { | |
| var result = string.Empty; | |
| try | |
| { | |
| var lineMatches = Regex.Matches(selected, ".*", RegexOptions.Multiline); | |
| foreach (var lineMatch in lineMatches) | |
| { | |
| var newline = Regex.Replace(lineMatch.ToString(), @"^\s*\//", ""); | |
| result = result + newline; | |
| } | |
| } | |
| catch (ArgumentException ex) | |
| { | |
| // Syntax error in the regular expression | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment