从带有文本引用的列表中解析

时间:2009-10-16 14:44:06

标签: c# string parsing

我想把这些字符串放在一个列表中,我该怎么做?保持是在前两行中找到的双""。我该如何解决这个问题?

scriptTxt = new string[]
{
    "#$language = "VBScript"",
    "#$interface = "1.0"",
    "crt.Screen.Synchronous = True",
    "Sub Main"
};

2 个答案:

答案 0 :(得分:5)

scriptTxt = new string[]
{
    "#$language = \"VBScript\"",
    "#$interface = \"1.0\"",
    "crt.Screen.Synchronous = True",
    "Sub Main"
};

或者

scriptTxt = new string[]
{
    @"#$language = ""VBScript""",
    @"#$interface = ""1.0""",
    "crt.Screen.Synchronous = True",
    "Sub Main"
};

答案 1 :(得分:1)

使用反斜杠转义引号。 (撇号是')

scriptTxt = new string[]
{
    "#$language = \"VBScript\"",
    "#$interface = \"1.0\"",
    "crt.Screen.Synchronous = True",
    "Sub Main"
};