2

I have this piece of code

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

This is already working but the spacing still remains in between text sent. how can I fix it or update my richtextbox? I am trying to eliminate the spacing in displaying a text to a richtextbox as shown

enter image description here

I want to show :

Hello
Hello
Hello

without the multiple newline or spacing.

iaskyou
  • 97
  • 12

1 Answers1

2

Document is not of type string.

EDIT

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);
Mihai Hantea
  • 1,741
  • 13
  • 16