0

I have problems with a MySQL data using C#. The string data in the database is a multiline text, I mean, with the " \n ". So I want to show it in a multiline texbox but it shows me everything in one line.

For example: the string in the database is: PICTURE OF THE DATABASE

"1

2"

But at the time of getting the data with the datareader and display it in a textbox in C # shows me: PICTURE OF THE PROGRAM

"1 2"

So how can i display it in separate lines? i mean, using the same format as in the database.

suffuko
  • 143
  • 1
  • 2
  • 12
  • Have you debugged the actual's string content using a breakpoint? What kind of textbox are you using? In `winforms` there is a property to make it multiline – Louis Feb 14 '17 at 19:02
  • yes, the textbox is set on MultiLine. I will check the breakpoint and see what happend in the console. – suffuko Feb 14 '17 at 19:05

2 Answers2

0

Your Textbox just doesn't like the "\n" as new line. You can either replace it with "\r\n" or Environment.NewLine by:

YourMultiLineString = YourMultiLineString.Replace('\n", Environment.NewLine);
Hasan
  • 2,444
  • 3
  • 30
  • 44
  • yes it is. I tried to display it in the Result Console, and it shows in differents lines, so i think is a problem with the textbox :c – suffuko Feb 14 '17 at 19:09
  • suffuko, can you run the following fuction, YourMultiLineString.Split(Environment.NewLine); , and tell me the size of the result array? – Hasan Feb 14 '17 at 19:12
  • suffuko, you can also try YourMultiLineString = YourMultiLineString.Replace('\n", Environment.NewLine); and see how that looks in the textbox – Hasan Feb 14 '17 at 19:15
0

\r\n is the proper line ending for windows, so try replacing \n with \r\n and see if the output displays correctly.

var test= mystring.Replace("\n", "\r\n");
mytextbox.Text = test;

Difference between \n and \r?

Community
  • 1
  • 1
Rick james
  • 824
  • 1
  • 11
  • 30