C # - why doesn't \ n \ r work?

In the database field, I am returning. I save the "body" of my letter (in case of change). In this case, I have the characters \ n \ r to get newlines. But it doesn't seem to work. Any thoughts:

So, the data in the field: 'TBD. \ R \ n \ nExpect'

And my output looks like this: TBD. \ R \ n \ nExpect

Thoughts?

+3
source share
4 answers

Escape sequences do not make sense in real string objects - only when the C # interpreter or compiler interprets them. You want to save the actual new line in the database field, not the 4 characters "\ r \ n".

+12
source

\r\n .. #. , db , ...

+2

, \r\n ,

myString = "\\r\\n";

, .

, , , , ..

\\n\\r .., :

replacedString = myString.Replace("\\r\\n", "\r\n");

.

+2

\r\n System.Environment.NewLine, ,

text.Replace("\r\n",  System.Environment.NewLine);
+1

Source: https://habr.com/ru/post/1758365/


All Articles