开发者

generating a CSV file, what carriage return character should I use?

开发者 https://www.devze.com 2022-12-14 21:30 出处:网络
I have to create a CSV file that represents an order. The file is going to be FTP\'d over, and imported into another system.

I have to create a CSV file that represents an order.

The file is going to be FTP'd over, and imported into another system.

What line feed/carriage return character should I use?

I am pretty sure the receiving end will be a microsoft system, is there a way to make it server agnostic开发者_JS百科?


You should to use System.Environment.NewLine, or ask for directions to that external application staff.


Use the default for whatever server creates the file. With FTP, transfer the file in text mode (the default mode, IIRC). It automatically converts line endings on the receiving side.

In summary, you do not need to do anything special. FTP already handles it in a server agnostic fashion.


Using only newlines (LF, '\n', chr(10), ^J, etc.) is supported by all operating systems. Individual applications vary in handling, especially in the Microsoft world.

Operating systems which internally use the CR LF pair—such as MSDOS, Windows, OpenVMS in stream_CRLF mode, etc.—are able to deal with LF-only.

Within FTP, use the ascii command for it to do the right thing with your file.


If your destination is a Microsoft Windows system, use CR+LF, which is the native Windows end of line.


Unfortunately you will have to make a choice between MS or non-MS/Unix(y) newlines.

MS is CR+LF, non-MS is just LF.

More info here http://en.wikipedia.org/wiki/Newline

On MS systems, many apps may well interpret an LF newline correctly, but some will not, e.g. Notepad. If you want to guarantee that all MS based apps will interpret your newlines correctly then you will have to use CR+LF, but this will come at the expense of double new lines in some apps on a non-MS system (some apps on a non-MS system will interpret CR+LF as a single newline).

0

精彩评论

暂无评论...
验证码 换一张
取 消