Reputation: 455
Hi i am doing a small project in C#, and i need to know what commands are comming from input source so i can do my work accordingly.. here is example...
textBox1.Text = "First line \nSecond line";
richTextBox1.Text = "First line \nSecond line";
Richtextbox shows this output:
First line
Second line
Textbox show this output:
First line Second line
please tell me how to show new line "\n" or return "\r" or similar input as a character output in text or richtextbox. so i can know that newline command is coming from input data.
for example text or richtext box will show this output.
First line \nSecond line
thankx in advance.
Upvotes: 5
Views: 16447
Reputation: 11314
Change Your text box property from single line to Multiline then it will change to new line
TextBox1.TextMode = TextBoxMode.MultiLine;
TextBox1.Text = "First line \n New line ";
Upvotes: 0
Reputation: 3439
For winforms application set
this.textBox1.Multiline = true;
and use "\r\n"
as
textBox1.Text = "First line \r\nSecond line";
Upvotes: 3
Reputation: 67075
You want to either prefix your string with @ or you can use a double slash before each n (\n). Both of these are ways of escaping the \ so that it displays instead of being treated as part of a new line.
@"This will show verbatim\n";
"This will show verbatim\\n";
You can utilize this by performing a Replace
on your incoming text
richTextBox1.Text = richTextBox1.Text.Replace("\n", "\n\\n");
richTextBox1.Text = richTextBox1.Text.Replace("\r\n", "\r\n\\n");
In the replace, I left the original linebreak so that it will be there, just followed by the displaying version. You can take those out if you dont want that. :)
Upvotes: 1
Reputation: 3793
Lets say that i have a string which have new line :
string st = "my name is DK" + Environment.NewLine + "Also that means it's my name";
Now that i want to show that there is new line in my text there you go :
textBox1.Text = st.Replace(Environment.NewLine, "%");
This will show the newline chat with % sign
Upvotes: 5
Reputation: 14522
Use the combination "\r\n" (or Environment.NewLine constant which contains just that).
Upvotes: 0