使用正则表达式时出错(验证正则表达式的代码)

我问你

我有这段代码

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

没有多个换行符或空格。

Mihai Hantea

文档不是字符串类型。

编辑

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);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章