c# - Remove Double LineBreak from RichTextBox to String -


i'm using visual studio 2015, c#, wpf, xaml.

i copy text richtextbox string , remove linebreaks.

a linebreak occurs if press shift+enter. enter causes double linebreak.

any text after double linebreak gets cut off textrange , copying string.

what double linebreak , how remove it?

richtextbox linebreak


xaml

<richtextbox x:name="rtbmessage" margin="10,10,10,50" /> 

c#

paragraph p = new paragraph();  // 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 string // remove linebreaks // string message = messagerichtextbox().replace(environment.newline, ""); 

removal 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", "") 

when retrieve richtextbox text

public string messagerichtextbox() {     rtbmessage.document = new flowdocument(p);     textrange textrange = new textrange(         rtbmessage.document.contentstart,         rtbmessage.document.contentend     );     return textrange.text; } 

you modify content of rtbmessage, wrong content. assume somehow reference 1st paragraph of document in p , truncate document 1st paragraph right there. try remove line rtbmessage.document = new flowdocument(p); , see if works you?

when user hits enter there no double-linebreak being inserted, new paragraph created. can verify trying place caret presumably empty line there - if it's double line break, there should empty line , caret can positioned on it.

anyway, document on screenshot should have 2 paragraph blocks this:

  • paragraph 1: "hello, world."
  • paragraph 2: "this test.<linebreak/>example."

hence assumption when re-create document trying retrieve content text, retain 1st paragraph there , discard rest.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -