简体   繁体   中英

RichTextBox in a single line in C#

Any way to convert a RichTextBox content and convert it to a single line in a String variable?

I have this:

string line = Document.Text;  //Convierte el contenido en una sola línea.
string singleLine=line.Replace("\r\n", " ");

When show that in a MessageBox, it still appears in multiple lines.

Thanks in advance!

The MessageBox has a finite length of space to show its message.
When there is no more space it continues to print your text on a newline but it doesn't modify anything in your message.

To check if your code has effectively removed the newlines try to print in the output window with

Console.WriteLine(singleline);

Also, I prefer to use Environment.NewLine instead of the escape codes specific to the current operating system

string singleLine=line.Replace(Environment.NewLine, " ");

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM