How to determine after which character the string ends?

This is the Paragraph-> Inlines of the Run type (this is not a regular line):

12 34 

These (above) values ​​will take completeTextRange.Text. But write in one line 1234

 foreach (Block r in text_rich.Document.Blocks) { if (r is Paragraph) { foreach (Inline i in ((Paragraph)r).Inlines) { if (i is Run) { var completeTextRange = new TextRange(i.ContentStart, i.ContentEnd); res.Append(completeTextRange.Text); 

    2 answers 2

    Apparently, so:

     foreach (Block r in text_rich.Document.Blocks) { if (r is Paragraph) { foreach (Inline i in ((Paragraph)r).Inlines) { if (i is Run) { var completeTextRange = new TextRange(i.ContentStart, i.ContentEnd); res.Append(completeTextRange.Text); } else if (i is LineBreak) { // строка закончилась, делайте что хотите // например res.Append("\n"); } } // абзац закончился, делайте что хотите, например res.Append("\n"); } } 
    • Oh sure, probably the author wanted to see it. - Anton Komyshan
    • this code is not executed else if (i is LineBreak) { - codename0082016
    • It does not reach else. Always Run is done - codename0082016
    • @ codename0082016: Okay, then tell me exactly how you get this text in your RichTextBox . It is important. - VladD
    • @ codename0082016: My code works correctly, it means that you received the text differently. - VladD

    Use the newline character: \n (regular expression). He will make a transfer to a new line. (If I understand your question correctly)

     sting str = "12 \n"+ "34"