String double quotes are replaced by empty in C #

I have a line.

There are no items to show in this view of the "Personal Documents"

then assign the variable str str

string str ="There are no items to show in this view 
of the \"Personal Documents\" library"

Now we plan to replace "\" and make it the actual string for the str object. I tried below but did not work

str = str.Replace(@"\",string.Empty);

I want the str value to be

string str ="There are no items to show in this view 
of the "Personal Documents" library"

I need to find this line in another line. When searching on this line. I could not find because str contains "\".

+3
source share
4 answers

If I understand your question correctly, you want to replace the \"string constant with ". It is not required, it is done by the compiler for you.

, \ (escape-) ", , " , .

escape- (, ), .

. :

Console.WriteLine("A string with a \" and a \\\" too.");

:

A string with a " and a \" too.
+3

There are no items to show in this view of the "Personal Documents"

# ", " # .

:

  • string str = "There are no items to show in this view of the \"Personal Documents\"";
                                                                 ↑                   ↑
    
  • string str = @"There are no items to show in this view of the ""Personal Documents""";
                 ↑                                                ↑                   ↑
    

, " .

str . ,

Console.WriteLine(str);

There are no items to show in this view of the "Personal Documents"

: (MSDN)


EDIT:

There are no items to show in this view of the "Personal Documents"

There are no items to show in this view of the Personal Documents

String.Replace Method :

string str = "There are no items to show in this view of the \"Personal Documents\"";

string result = str.Replace("\"", "");

"\"" , " ( ), "" - .

+13
string str ="There are no items to show in this view of the \"Personal Documents\" library";

.

str Console.Write .

+2

:

string str = @"There are no items to show in this view of the ""Personal Documents"" library"
0
source

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


All Articles