Split String in C#
Posted
by ritu
on Stack Overflow
See other posts from Stack Overflow
or by ritu
Published on 2010-05-11T01:37:38Z
Indexed on
2010/05/11
1:44 UTC
Read the original article
Hit count: 419
c#
I thought this will be trivial but I can't get this to work.
Assume a line in a CSV file: "Barak Obama", 48, "President", "1600 Penn Ave, Washington DC"
string[] tokens = line.split(',')
I expect this: "Barak Obama" 48 "President" "1600 Penn Ave, Washington DC"
but the last token is 'Washington DC' not "1600 Penn Ave, Washington DC".
Is there an easy way to get the split function to ignore the comma within quotes?
© Stack Overflow or respective owner