Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with escape character

Tags:

c#

escaping

I have a string variable. And it contains the text:

\0#«Ия\0ьw7к\b\0E\0њI\0\0ЂЪ\n

When I try to add it to the TextBox control, nothing happens.Because \0 mean END.

How do I add text as it is?

UPDATE: The text is placed in the variable dynamically.Thus, @ is not suitable.

like image 383
user348173 Avatar asked Dec 02 '22 04:12

user348173


2 Answers

Is the idea that you want to display the backslashes? If so, the backslashes will need to be in the original string.

If you're getting that text from a string literal, it's just a case of making it a verbatim string literal:

string text = @"\0#«Ия\0ьw7к\b\0E\0њI\0\0ЂЪ\n";

If want to pass in a string which really contains the Unicode "nul" character (U+0000) then you won't be able to get Windows to display that. You should remove those characters first:

textBox.Text = value.Replace("\0", "");
like image 96
Jon Skeet Avatar answered Dec 03 '22 17:12

Jon Skeet


"\\0#«Ия\\0ьw7к\\b\\0E\\0њI\\0\\0ЂЪ\\n"

or

@"\0#«Ия\0ьw7к\b\0E\0њI\0\0ЂЪ\n"
like image 37
xcud Avatar answered Dec 03 '22 17:12

xcud