请帮我分解字符串“,”将“desc,a”作为结果中的单个项目。
string s="\"desc,a\",True,True,False,True,0,1,red,1,1,"
先谢谢。
答案 0 :(得分:2)
您可以使用正则表达式匹配带引号和不带引号的项目:
string[] items =
Regex.Matches(s, @"""[^""]*""|[^,]+")
.Cast<Match>()
.Select(x => x.Value)
.ToArray();
说明:
""[^""]*"" - matches an item with quotation marks
(quot, zero or more non-quot character, quot)
| - or operator
[^,]+ - matches an item without quotation marks
(one or more characters other than comma)
答案 1 :(得分:-1)
我建议你看一下正则表达式: http://msdn.microsoft.com/en-us/library/az24scfc.aspx