Reputation: 206
Please help me to split string with "," having "desc,a" as single item in result.
string s="\"desc,a\",True,True,False,True,0,1,red,1,1,"
Thanks in Advance.
Upvotes: 1
Views: 64
Reputation: 700212
You can use a regular expression to match items with and without quotation marks:
string[] items =
Regex.Matches(s, @"""[^""]*""|[^,]+")
.Cast<Match>()
.Select(x => x.Value)
.ToArray();
Explanation:
""[^""]*"" - 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)
Upvotes: 2
Reputation: 316
I would suggest you to take a look at regular expressions: http://msdn.microsoft.com/en-us/library/az24scfc.aspx
Upvotes: -1