我有这段代码
string myText = new TextRange(mainWindow.richtextbox2.Document.ContentStart,
mainWindow.richtextbox2.Document.ContentEnd).Text;
//replace two or more consecutive spaces with a single space, and
//replace two or more consecutive newlines with a single newline.
var str = Regex.Replace(myText, @"( |\r?\n)\1+", "$1", RegexOptions.Multiline);
mainWindow.Dispatcher.Invoke(new Action(() =>
mainWindow.richtextbox2.Document.Blocks.Add(new Paragraph(new
Run("Hello")))));
这已经可以工作,但发送的文本之间仍然存在间距。 我该如何修复它或更新我的 Richtextbox?我正在尝试消除在 Richtextbox 中显示文本时的间距,如图所示
我想展示:
Hello
Hello
Hello
没有多个换行符或空格。
最佳答案
文档不是字符串类型。
编辑
string myText = new TextRange(richtextbox2.Document.ContentStart, richtextbox2.Document.ContentEnd).Text;
//replace two or more consecutive spaces with a single space, and
//replace two or more consecutive newlines with a single newline.
var str = Regex.Replace(myText, @"( |\r?\n)\1+", "$1", RegexOptions.Multiline);
关于c# - 使用正则表达式时出错(验证正则表达式的代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22090288/