public static string Clean(string Text, TextCleanType CleanType) { if ((CleanType & TextCleanType.RemoveExtraSpaces) == TextCleanType.RemoveExtraSpaces) { Text = Regex.Replace(Text, "\\s+"," ").Trim(); } else if((CleanType & TextCleanType.RemoveExtraSpaces) == TextCleanType.RemoveNewLines) { Text = Regex.Replace(Text, "\\r\\n","").Trim(); } return Text; }
public static string JoinFiles(string FileNameTemplate, int FilesCount, string OutputFileName = null, int FilesCountStart = 1, string Separator = "\r\n", TextCleanType CleanBeforeJoin = TextCleanType.RemoveExtraSpaces | TextCleanType.RemoveNewLines) { string txt = null; var list = new List<string>(); for (var i = FilesCountStart; i < FilesCountStart + FilesCount; i++) { txt = File.ReadAllText(string.Format(FileNameTemplate, i)); txt = TextClean.Clean(txt, CleanBeforeJoin); list.Add(txt); } txt = string.Join(Separator, list); if (!string.IsNullOrEmpty(OutputFileName)) File.WriteAllText(OutputFileName, txt); return txt; }