按照标点进行段落排版的C#代码
public static class FormatTxT
{
public static bool after_is_en(this string str)
{
return Regex.IsMatch(str, ".*[a-zA-Z]$");
}
public static bool before_is_en(this string str)
{
return Regex.IsMatch(str, "^[a-zA-Z]");
}
public static bool str_is_split(this string str)
{
return Regex.IsMatch(str, ".*[。?!.?!:]$");
}
public static string format_txt(this string strlines)
{
string[] strings = strlines.Split(new string[] {System.Environment.NewLine}, StringSplitOptions.None);
string childstr = "";
StringBuilder str = new StringBuilder();
for (int i = 0; i < strings.Length; i++)
{
string currentstr = strings[i].Trim();
if (i>0)
{
string laststr = strings[i - 1].Trim();
if (currentstr.after_is_en() && laststr.before_is_en())
{
str.Append(" ");
}
}
str.Append(currentstr);
if (currentstr.str_is_split())
{
str.Append(System.Environment.NewLine);
}
}
return str.ToString();
}
}