using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var text = "int rn = 0; //comment1.0\r\n" + "int r = 0; //comment2.\r" + "int n = 0; //comment3.\n" + "end"; Console.WriteLine(RemoveLineEndComment(text)); } public static string RemoveLineEndComment(string text) { var RegexRemoveLineEndComment = new Regex(@"\s*//[^\r\n]*", RegexOptions.Multiline); return RegexRemoveLineEndComment.Replace(text, string.Empty); } }