使用C#将数据转换为csv格式. ? [英] Converting data to csv format using C#. ?

查看:225
本文介绍了使用C#将数据转换为csv格式. ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有几个与主题相关的问题.

如何将文本文件中的数据,甚至直接从列表缓冲区中的数据转换为csv格式?哪些类/功能/属性会派上用场?谁能给我一个函数示例?

谢谢,

Hi all

I have a couple of questions relating to my subject line.

How would I convert data in a text file, or even directly from say, a list buffer, to csv format? What class/functions/properties would come in handy? Can anyone maybe give me a function example?

Thanks,

推荐答案

您好,RudolfErasmum,

String类将具有方便的功能,例如"String.Split",因为要创建CSV,您需要通过预定的
分隔原始文本 特点.

拆分文本后,StringBuilder类将很方便地重建字符串,并在需要时插入逗号.我建议使用的一种方法是追加.

然后看一下StreamWriter类,将您的内存流保存到CSV文件中可能会有所帮助.

MSDN有许多与这些类和相关方法有关的信息.

希望能有所帮助.

Larrythemule
Hi there RudolfErasmum,

The String class will have handy functions like ''String.Split'', as to create a CSV you will need to delimit your original text by a predetermined
character.

After you have split down your text the StringBuilder class will be a handy to rebuild your strings inserting a comma where required. A method that I would suggest using is Append.

It might help then to take a look at the StreamWriter class, to save your memory stream to a CSV file.

MSDN has a lot of information relating to these classes and the related methods.

Hope that helps.

Larrythemule




在Codeproject上有很多涉及此主题的文章.这是我发现的一些东西:

http://www.codeproject.com/KB/database/Cs_CSV_import_export.aspx [ ^ ]

http://www.codeproject.com/KB/database/filehelpers.aspx [ ^ ]

http://www.codeproject.com/KB/cs/CsvReaderAndWriter.aspx [ ^ ]
Hi,

there are lots of articles on Codeproject that cover this topic. Here are some I found:

http://www.codeproject.com/KB/database/Cs_CSV_import_export.aspx[^]

http://www.codeproject.com/KB/database/filehelpers.aspx[^]

http://www.codeproject.com/KB/cs/CsvReaderAndWriter.aspx[^]


读写文件看
System.IO区域StringReader/StringWriter


操纵字符串:

StringBulder建立线条

阅读

Read and writing file look at
System.IO area StringReader/StringWriter


manipulating strings:

StringBulder to build up lines

to read in

string[] fields = string.Split('','');


这篇关于使用C#将数据转换为csv格式. ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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