拆分逗号分隔值(CSV) [英] Splitting Comma Separated Values (CSV)

查看:162
本文介绍了拆分逗号分隔值(CSV)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何分割在C锋利的CSV文件?以及如何显示呢?

How to split the CSV file in c sharp? And how to display this?

推荐答案

我已经得到了我的查询结果。它像简单的像我一直使用io.file读取文件。和所有的文本被存储为一个字符串。从那以后,我分裂了分隔符。该代码如下所示

I had got the result for my query. its like simple like i had read a file using io.file. and all the text are stored into a string. After that i splitted with a seperator. The code is shown below.

using System;
using System.Collections.Generic;
using System.Text;

namespace CSV
{
    class Program
    {
        static void Main(string[] args)
        {

            string csv = "user1, user2, user3,user4,user5";

            string[] split = csv.Split(new char[] {',',' '});
            foreach(string s in split)
            {
                if (s.Trim() != "")
                    Console.WriteLine(s);
            }
            Console.ReadLine();
        }
    }
}

这篇关于拆分逗号分隔值(CSV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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