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

时间:2016-01-24 10:48:42

标签: c#

我已经给出了对API的调用,返回以下内容

“\” 已批准\ “”

在c#中,如何将其转换为普通字符串?

3 个答案:

答案 0 :(得分:0)

试试这个

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

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

   Console.WriteLine(r);
}

答案 1 :(得分:0)

我尝试使用字符串替换无效。

这是我最终如何做到这一点,这只是剥离了一切不是一个角色

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

答案 2 :(得分:0)

https://docs.python.org/2/library/csv.html

和String.TrimEnd

import csv

TEST_TEXT = """\
hello,one,two,three
world,four,five,six
goodbye,one,two,three"""

TEST_FILE = TEST_TEXT.split("\n")
#file objects iterate over newlines anyway
#so this is how it would be when opening a file

#this would be the minimum needed to use the csv reader object:
for row in csv.reader(TEST_FILE):
    print(row)

#or to get a list of all the rows you can use this:
as_list = list(csv.reader(TEST_FILE))

#splitting off the first element and using it as the key in a dictionary
dict_I_call_matrix = {row[0]:row[1:] for row in csv.reader(TEST_FILE)}
print(dict_I_call_matrix)



without_csv = [row.split(",")  for row in TEST_FILE] #...row in TEST_TEXT.split("\n")]

matrix = [row[1:] for row in without_csv]
labels = [row[0] for row in without_csv]

或者可能更合适 - String.TrimStart

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