Newline character

Does your software support newline characters from other systems?

Linux/BSD    linefeed         ^J    10     x0A
Windows/IBM  return linefeed  ^M^J  13 10  x0D x0A
old Macs     return           ^M    13     x0D
others?

For reasons of insanity, I'm going to use the Linux version of the newline in my text files. But, when I bring my text files to say Windows, some programs do not reproduce newline characters very well in my text. How do you handle this?

+3
source share
8 answers

As the saying goes, be strict in what you write and liberal in what you read.

Your application should be able to work normally by reading both ends of the line. If you want to use line feeds and potentially upset Windows users, that's fine.

, , , , .

( Cygwin Windows, )

+3

Python ( /), crlf.py lfcr.py, Windows Unix/Linux.

[]

+1

.NET Environment.NewLine, , ( CR + LF CR LF) . , Mono.

+1

, , Windows ( Notepad) . , Windows, - crlf.

- . , C, fopen(..., "r"), ( ) .

0

, "", . - . , Notepad . , Microsoft, . Vista, , , XP. ?

0

, ( ) , . : FTP Ascii, ...

, Notepad - , LF...

, , , , Windows Unix, , .

0

, .

http://unicode.org/standard/reports/tr13/tr13-5.html

, MacOS. , .

Unix. Windows. Windows . , . Word Excel. , , , - .

Unix , . Unix, .

PS. , Windows , Unix , Unix.

0

, , "", - :

string convertLineBreaks(String line, String lineBreakYouWant) {
  replace all ^M^J or ^M or ^J in line with lineBreakYouWant

  return line
}

Edit: I suspect that after reading your question again, you mean how you deal with programs of other nations that cannot handle incorrect (for the target system) line breaks.

I would suggest either 1) use a program that can work, or 2) run your files through a script that finds line breaks of any type and then converts them to any type suitable for your system.

-2
source

Source: https://habr.com/ru/post/1697554/


All Articles