简体   繁体   English

如何从C#中的字符串文字中删除斜杠和引号

[英]how to remove slashes and quotes from a string literal in c#

A call to an API I have been given is returning the following 对我给出的API的调用返回以下内容

"\\"Approved\\"" “ \\”已批准\\“”

In c#, how can I convert this into a normal string? 在C#中,如何将其转换为普通字符串?

Try this 尝试这个

static void Main(string[] args)
{
   var s = "\"Approved\"";

   var r = s.Replace("\"", string.Empty);                  

   Console.WriteLine(r);
}

I tried using string replace to no avail. 我尝试使用字符串替换无济于事。

Here is how i did it eventually, this just strips everything out that isn't a character 这是我最终的做法,这只是去除了不是字符的所有内容

myString = = new string((from c in hasAccount where char.IsWhiteSpace(c) || char.IsLetterOrDigit(c) select c).ToArray());

String.TrimStart String.TrimStart

and String.TrimEnd 和String.TrimEnd

var r=s.TrimStart('"').TrimEnd('"');

or probably more appropriate just - String.Trim 或者可能更合适-String.Trim

var r=s.Trim('"');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM