1

请帮助我用“,”拆分字符串,结果中将“desc,a”作为单个项目。

string s="\"desc,a\",True,True,False,True,0,1,red,1,1,"

提前致谢。

4

2 回答 2

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)
于 2013-07-07T10:51:17.633 回答
-1

我建议你看看正则表达式:http: //msdn.microsoft.com/en-us/library/az24scfc.aspx

于 2013-07-07T10:46:14.120 回答