Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

c# - Splitting a CSV and excluding commas within elements

I've got a CSV string an I want to separate it into an array. However the CSV is a mix of strings and numbers where the strings are enclosed in quotes and may contain commas.

For example, I might have a CSV as follows:

1,"Hello",2,"World",3,"Hello, World"

I would like it so the string is split into:

1
"Hello"
2
"World"
3
"Hello, World"

If I use String.Split(','); I get:

1
"Hello"
2
"World"
3
"Hello
World"

Is there an easy way of doing this? A library that is already written or do I have to parse the string character by character?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The "A Fast CSV Reader" article on Code Project. I've used it happily many times.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...