RosettaCodeData/Task/Strip-comments-from-a-string/C-sharp/strip-comments-from-a-string.cs

10 lines
411 B
C#
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
using System.Text.RegularExpressions;
string RemoveComments(string str, string delimiter)
{
//regular expression to find a character (delimiter) and
// replace it and everything following it with an empty string.
//.Trim() will remove all beginning and ending white space.
return Regex.Replace(str, delimiter + ".+", string.Empty).Trim();
}