3
votes

Currently in my application I have a string that is read in from an XML file however the whole string is concatenated together and I want to be able to split up the string over multiple lines of the 'RichTextBox' at specific points that I choose in the XML node for that string.

For example my string before formatting as it sits in the XML node:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eleifend arcu vel tellus aliquam eget aliquet orci dignissim. Integer volutpat congue elementum. In commodo porta sem. Phasellus commodo consectetur hendrerit. Integer bibendum consequat elit nec ultricies. Fusce facilisis elit in justo facilisis sagittis. Aenean eget risus placerat dui hendrerit pharetra sed in neque. Maecenas vehicula iaculis lectus eget scelerisque. Fusce sed consequat elit.

The result I desire after formatting in my application:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eleifend arcu vel tellus aliquam eget aliquet orci dignissim. Integer volutpat congue elementum. In commodo porta sem.

Phasellus commodo consectetur hendrerit. Integer bibendum consequat elit nec ultricies. Fusce facilisis elit in justo facilisis sagittis.

Aenean eget risus placerat dui hendrerit pharetra sed in neque. Maecenas vehicula iaculis lectus eget scelerisque. Fusce sed consequat elit.

Is it possible to split up one long concatenated string over multiple lines like this for a 'RichTextBox' by including the formatting directly within the XML node / string itself rather than hard coding where each new line needs to be?

2

2 Answers

4
votes

I ended up finding my own solution to this problem; it's similar to what has been said but instead what this does is check for a specific character in the string and then remove it and in its place puts in a new line.

myLongString = myLongString.Replace("@", "" + System.Environment.NewLine);

The example above simply checks the string for the @ symbol and then removes it and adds a new line. This then allows the string to be formatted with a new line wherever the specified keyword or symbol appears which means that the formatting of the string can be stored with the XML node and then interpreted.

0
votes

Yes. You can use Environment.NewLine

richTextBox1.Text += "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eleifend arcu vel tellus aliquam eget aliquet orci dignissim. Integer volutpat congue elementum. In commodo porta sem."
    + Environment.NewLine + Environment.NewLine + 
    " Phasellus commodo consectetur hendrerit. Integer bibendum consequat elit nec ultricies. Fusce facilisis elit in justo facilisis sagittis."
    + Environment.NewLine + Environment.NewLine + 
    " Aenean eget risus placerat dui hendrerit pharetra sed in neque. Maecenas vehicula iaculis lectus eget scelerisque. Fusce sed consequat elit.";

embeded new line is \n

richTextBox1.Text += "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eleifend arcu vel tellus aliquam eget aliquet orci dignissim. Integer volutpat congue elementum. In commodo porta sem.\n\n Phasellus commodo consectetur hendrerit. Integer bibendum consequat elit nec ultricies. Fusce facilisis elit in justo facilisis sagittis.\n\n Aenean eget risus placerat dui hendrerit pharetra sed in neque. Maecenas vehicula iaculis lectus eget scelerisque. Fusce sed consequat elit.";