我正在使用多行文本框,我可以通过连续键入消息键入消息,或者在按几次回车键的同时键入文本。
所以我的输入可能如下:
This is some text
this is come other text
and some other text
使用SendKeys.Send(txtText.Text + "{enter}");
我的输出如下:
This is some text
this is come other text
and some other text
如何删除不必要的新行?
答案 0 :(得分:2)
尝试,
string text=txtText.Text;
txtText.Text=string.Join(Environment.NewLine,
text.Split(new string[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries));