Split String in C#

前端 未结 9 1010
萌比男神i
萌比男神i 2020-12-28 09:10

I thought this will be trivial but I can\'t get this to work.

Assume a line in a CSV file: \"Barack Obama\", 48, \"President\", \"1600 Penn Ave, Washington DC

9条回答
  •  滥情空心
    2020-12-28 09:44

    I see from the bigger picture that you are actually trying to parse CSV input. So instead of advising on how to split the string properly, I would instead recommend you to use a CSV parser to do this kind of thing.

    A Fast CSV Reader

    One that I would recommend is the library (source code available) that you can get from this CodeProject page: http://www.codeproject.com/KB/database/CsvReader.aspx

    I personally use it myself and like it. It's a .NET native code and a lot faster than using OLEDB (which also can do the CSV parsing for you, but believe me, it's slow).

提交回复
热议问题