将DataTable的单个列转换为CSV [英] Convert single column of a DataTable to CSV

查看:162
本文介绍了将DataTable的单个列转换为CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VB.NET,将数据表的单个列转换为CSV的最简洁的方法是什么?这些值是整数,所以我不需要担心字符转义或编码。

Using VB.NET, what is the most concise way to convert a single column of a DataTable to a CSV? The values are integers, so I don't need to worry about character escaping or encoding.

推荐答案

转换为CSV?如果你想生成一个以逗号分隔的字符串,你可以使用这个( tbl 是你的DataTable和 Int-Column 是DataColumn的名称):

What do you mean with "convert to CSV"? If you want to generate a string with comma-separated values, you can use this(tbl is your DataTable and Int-Column is the name of the DataColumn):

String.Join(",", (From row In tbl.AsEnumerable Select row("Int-Column")).ToArray)

CSV通常是一种文件格式列由逗号(或其他分隔符)分隔,并且行由新行分隔。因此,你只需要替换 String.Join(, with String.Join(Environment.NewLine

A CSV normally is a file-format where the columns are separated by comma(or other separators) and the rows are separated by new lines. Hence you simply have to replace String.Join("," with String.Join(Environment.NewLine

这篇关于将DataTable的单个列转换为CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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