Welcome

首页 / 软件开发 / C# / C#根据标点符号分行

C#根据标点符号分行2009-12-24根据标点符号分行时,首先要使用string类的Split方法分割字符串,然后再通过“ ”回车换行符将分割的字符串换行显示。根据标点符号分行的关键代码如下:

string oldstr = textBox1.Text.Trim(); 
string[] newstr = oldstr.Split("。");
for (int i = 0; i < newstr.Length; i++)
{
if (richTextBox1.Text == "")
richTextBox1.Text = newstr[i].ToString();
else
richTextBox1.Text += " " + newstr[i].ToString();
}