C# String.Replace double quotes and Literals

前端 未结 4 767
孤街浪徒
孤街浪徒 2021-02-02 14:58

I\'m fairly new to c# so that\'s why I\'m asking this here.

I am consuming a web service that returns a long string of XML values. Because this is a string all the attri

4条回答
  •  遥遥无期
    2021-02-02 15:16

    the following statement in C#

    string xmlSample = ""
    

    will actually store the value

    
    

    whereas

    string xmlSample = @"";
    

    have the value of

    
    

    for the second case, you need to replace the slash () by empty string as follow

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

    the result will be

    
    

    P.S.

    1. slash (\) is default escape character in C#
    2. to ignore slashes, use @ at the beginning of string
    3. if @ is used, the escape character is double quote (")

提交回复
热议问题