I'm using Visual Studio 2015, C#, WPF, XAML.
I copy the text from a RichTextBox to a string and remove any LineBreaks.
A LineBreak occurs if you press Shift+Enter. But just Enter causes a Double LineBreak.
Any text after the Double LineBreak gets cut off from TextRange and copying to the string.
What is this Double LineBreak and how do I remove it?
XAML
<RichTextBox x:Name="rtbMessage" Margin="10,10,10,50" />
C#
Paragraph p = new Paragraph();
// Get RichTextBox TextRange Method
//
public String MessageRichTextBox()
{
rtbMessage.Document = new FlowDocument(p);
TextRange textRange = new TextRange(
rtbMessage.Document.ContentStart,
rtbMessage.Document.ContentEnd
);
return textRange.Text;
}
// RichTextBox to String
// Remove LineBreaks
//
string message = MessageRichTextBox().Replace(Environment.NewLine, "");
Removal I have tried:
https://stackoverflow.com/a/6750310/6806643
Regex.Replace(MessageRichTextBox(), @"[\u000A\u000B\u000C\u000D\u2028\u2029\u0085]+", string.Empty);
.Replace(Environment.NewLine, "")
.Replace("\n", "")
.Replace("\r\n", "")
.Replace("\u2028", "")
.Replace("\u000A", "")
.Replace("\u000B", "")
.Replace("\u000C", "")
.Replace("\u000D", "")
.Replace("\u0085", "")
.Replace("\u2028", "")
.Replace("\u2029", "")
