Split a string ignoring quoted sections

前端 未结 13 2379
别跟我提以往
别跟我提以往 2020-12-06 00:15

Given a string like this:

a,\"string, with\",various,\"values, and some\",quoted

What is a good algorithm to split this based on

13条回答
  •  再見小時候
    2020-12-06 00:37

    Looks like you've got some good answers here.

    For those of you looking to handle your own CSV file parsing, heed the advice from the experts and Don't roll your own CSV parser.

    Your first thought is, "I need to handle commas inside of quotes."

    Your next thought will be, "Oh, crap, I need to handle quotes inside of quotes. Escaped quotes. Double quotes. Single quotes..."

    It's a road to madness. Don't write your own. Find a library with an extensive unit test coverage that hits all the hard parts and has gone through hell for you. For .NET, use the free FileHelpers library.

提交回复
热议问题