I have a RichTextBox that needs to accept returns. When I read its document content, it seems to be adding an extra line break. For example, the following code:
TextRange rtbText = new TextRange(rtBox.Document.ContentStart, rtBox.Document.ContentEnd);
Console.WriteLine(Char.ConvertFromUtf32(34) + rtbText.Text + Char.ConvertFromUtf32(34));
will output
"test
"
even though the visible rtBox content on screen is simply test
on a single line. I expect the output to be:
"test"
EDIT: I am just using the rtbText.Text
for debugging purposes. The actual usage of that rtbText
TextRange object will be to save to a MemoryStream using rtbText.Save(ms, DataFormats.Rtf)
Can someone please assist with removing this extra line break. Thanks
只需使用Trim()或什至更好的TrimEnd()即可解决问题
Console.WriteLine(Char.ConvertFromUtf32(34) + rtbText.Text.TrimEnd( '\r', '\n' ) + Char.ConvertFromUtf32(34));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.