Skip to content

Instantly share code, notes, and snippets.

@tecnocrata
Created July 23, 2014 20:50
Show Gist options
  • Select an option

  • Save tecnocrata/e69abbff5295bdf19849 to your computer and use it in GitHub Desktop.

Select an option

Save tecnocrata/e69abbff5295bdf19849 to your computer and use it in GitHub Desktop.
Comment / Uncomment C# Code
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