如何使用嵌入式逗号读取字段必须使用双引号字符分隔。 [英] How Do I Read Fields With Embedded Commas Must Be Delimited With Double-Quote Characters.

查看:82
本文介绍了如何使用嵌入式逗号读取字段必须使用双引号字符分隔。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么读带有嵌入式逗号的字段必须用双引号字符分隔。



1997,福特,E350,超级豪华卡车



plz帮我几个代码从csv文件文本(ASP.net)进入表格



输出



年份车型modelno型号名称



1997款福特E350超级豪华卡车

how do i read Fields with embedded commas must be delimited with double-quote characters.

1997,Ford,E350,"Super, luxurious truck"

plz help me with few codes to get it into table from csv file text (ASP.net)

output

year car modelno modelname

1997 Ford E350 Super luxurious truck

推荐答案

static void EmbeddedCommas()
        {
            string input =@"1997,Ford,E350,""Super, luxurious truck""";
            string[] inputArray;
            inputArray = input.Split(',');
            int count = 0;
            int maxCount = 4;
            string[] outputArray = new string[maxCount];

            foreach (var item in inputArray)
            {
                if (count < maxCount - 1)
                {
                    outputArray[count] = item;
                    input = input.Remove(0, outputArray[count].Length + 1);
                    count++;
                }
                else
                {
                    outputArray[count] = input.Replace('"',' ');
                }

            }

            foreach (var item in outputArray)
            {
                Console.WriteLine(item);
            }
            Console.ReadLine();
        }


csv C omma S eparated V alues

Look对于可以读取csv文件的库!
csv: Comma Separated Values
Look for a library which can read csv files!


这篇关于如何使用嵌入式逗号读取字段必须使用双引号字符分隔。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆