Reading CSV file and storing values into an array

后端 未结 19 1746
猫巷女王i
猫巷女王i 2020-11-22 06:35

I am trying to read a *.csv-file.

The *.csv-file consist of two columns separated by semicolon (\";\").

I am able

19条回答
  •  执念已碎
    2020-11-22 07:19

    I have spend few hours searching for a right library, but finally I wrote my own code :) You can read file (or database) with whatever tools you want and then apply the following routine to each line:

    private static string[] SmartSplit(string line, char separator = ',')
    {
        var inQuotes = false;
        var token = "";
        var lines = new List();
        for (var i = 0; i < line.Length; i++) {
            var ch = line[i];
            if (inQuotes) // process string in quotes, 
            {
                if (ch == '"') {
                    if (i

提交回复
热议问题