请帮助我用“,”拆分字符串,结果中将“desc,a”作为单个项目。
string s="\"desc,a\",True,True,False,True,0,1,red,1,1,"
提前致谢。
请帮助我用“,”拆分字符串,结果中将“desc,a”作为单个项目。
string s="\"desc,a\",True,True,False,True,0,1,red,1,1,"
提前致谢。
您可以使用正则表达式来匹配带引号和不带引号的项目:
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)
我建议你看看正则表达式:http: //msdn.microsoft.com/en-us/library/az24scfc.aspx