C# .csv 和 .txt 文件之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14620125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between a .csv and a .txt file
提问by DevT
What is the difference between these two file format.
这两种文件格式有什么区别。
i found this from Here
我从这里找到了这个
.txt File:This is a plain text file which can be opened using a notepad present on all desktop PCs running MS Windows any version. You can store any type of text in this file. There is no limitation of what so ever text format. Due to ease of use for end users many daily data summery providers use .txt files. These files contain data which is properly comma seperated.
.txt 文件:这是一个纯文本文件,可以使用运行 MS Windows 任何版本的所有台式电脑上的记事本打开。您可以在此文件中存储任何类型的文本。没有任何文本格式的限制。由于易于最终用户使用,许多日常数据摘要提供者使用 .txt 文件。这些文件包含正确逗号分隔的数据。
.csv File: abreviation of "comma seperated values"This is a special file extension commonly used by MS Excel. Basically this is also a plain text file but with a limitation of comma seperated values. Normally when you double click this type of file it will open in MS Excel. If you do not have MS Excel installed on your computer or you find Notepad easy to use then you also can open this file in a notepad by right clicking the file and from the menu select "Open With" and then choose notepad.
.csv 文件:“逗号分隔值”的缩写这是 MS Excel 常用的特殊文件扩展名。基本上这也是一个纯文本文件,但有逗号分隔值的限制。通常,当您双击此类文件时,它将在 MS Excel 中打开。如果您的计算机上没有安装 MS Excel 或者您发现记事本易于使用,那么您也可以通过右键单击该文件并从菜单中选择“打开方式”然后选择记事本在记事本中打开此文件。
My Question :
我的问题 :
- what does means comma seperated value?
- if i'm going to create .csv file using c#, does i need to write file using
StreamWriter
and does it need to only change the the extention to .csv? - if so do i need to change the writing string with commas?
- 逗号分隔值是什么意思?
- 如果我要使用 c# 创建 .csv 文件,我是否需要使用编写文件
StreamWriter
并且是否只需要将扩展名更改为 .csv? - 如果是这样,我需要用逗号更改写作字符串吗?
thanx....
谢谢....
采纳答案by Habib
what does means comma seperated value?
逗号分隔值是什么意思?
Values separated by Comma, for example.
例如,用逗号分隔的值。
Name,Id,3,Address
if i'm going to create .csv file using c#, does i need to write file using StreamWriter and does it need to only change the the extention to .csv?
如果我要使用 c# 创建 .csv 文件,我是否需要使用 StreamWriter 编写文件,是否只需要将扩展名更改为 .csv?
Changing extension of the file will help you in opening it in MS Excel, other than that it can be anything and you can still open it through your code (StreamReader)
更改文件的扩展名将帮助您在 MS Excel 中打开它,除此之外它可以是任何东西,您仍然可以通过代码打开它 (StreamReader)
if so do i need to change the writing string with commas?
如果是这样,我需要用逗号更改写作字符串吗?
Yes, separate your values with Comma
, or you can use any other delimiter you like. It can be semicolon ;
as well since ,
in some languages/cultures is used for decimal separator.
是的,用 分隔您的值Comma
,或者您可以使用任何其他您喜欢的分隔符。它也可以是分号;
,因为,
在某些语言/文化中用于小数分隔符。
回答by Justin Donohoo
CSV is structured like this:
CSV 的结构如下:
"value","value1,"value2"
“值”、“值 1”、“值 2”
A text file can be anything from delimited, to free form , fixed width, jagged right, etc...
文本文件可以是从分隔符到自由格式、固定宽度、右锯齿等任何内容...
CSV files can be a pain in the ass if you have commas in your data, and don't properly qualify the values.
如果您的数据中有逗号,并且没有正确限定值,CSV 文件可能会很麻烦。
I typically create tab delimited or pipe delimited files.
我通常创建制表符分隔或管道分隔的文件。
回答by daryal
From the perspective of programming, file extensions do not make a difference. In fact you may write comma seperated values inside a txt file.
从编程的角度来看,文件扩展名没有区别。事实上,您可以在 txt 文件中写入逗号分隔值。
Comma seperated values indicates the values are just seperated with commas; this is helpful if you want to store some data and share it accross multiple systems (on the otherhand XML is a better option).
逗号分隔值表示仅用逗号分隔的值;如果您想存储一些数据并在多个系统之间共享它,这会很有帮助(另一方面,XML 是更好的选择)。
Assume you need to store name, age and location;
假设您需要存储姓名、年龄和位置;
TilT,25,Germany
is a comma seperated data.
是逗号分隔的数据。
In the scope of c#, you need to add commas between your values and you may save it as a CSV file or a TXT file; it makes no difference.
在c#范围内,你需要在你的值之间添加逗号,你可以将其保存为CSV文件或TXT文件;没有什么不同的。