문제

소프트웨어가 다른 시스템에서 Newline 문자를 처리합니까?

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

광기의 이유로, 나는 내 텍스트 파일에서 Newline 문자의 Linux 버전을 사용하고 있습니다. 그러나 텍스트 파일을 Windows라고 말하면 일부 프로그램은 내 텍스트에서 Newline 문자와 잘 어울리지 않습니다. 이것을 어떻게 처리 하시겠습니까?

도움이 되었습니까?

해결책

그들이 말했듯이, 당신이 쓰는 내용에 엄격하고 당신이 읽은 내용에서 자유주의하십시오.

응용 프로그램은 두 라인 엔딩을 모두 읽을 수 있어야합니다. LineFeeds를 사용하고 잠재적으로 화를 낸 Windows 사용자를 사용하려면 괜찮습니다.

그러나 메모장을 위해 저장하십시오. 제가하는 대부분의 프로그램은 두 방법 모두에 만족하는 것 같습니다.

(그리고 나는 Windows에서 Cygwin을 사용하여 모든 것을 흥미롭게 만듭니다)

다른 팁

표준 파이썬 분포에는 Windows와 Unix/Linux 라인 엔딩 사이에서 변환 할 수있는 crlf.py 및 lfcr.py라는 두 개의 명령 줄 스크립트 (도구/스크립트)가 제공됩니다.

원천

.NET에서는 새로운 라인이 표시됩니다 Environment.NewLine, 따라서 프레임 워크는 런타임에 사용하기 위해 시스템의 새로운 라인 (CR+LF 또는 CR 만 또는 LF 만 해당)이 무엇이든 취하는 방식으로 설계되었습니다. 물론 이것은 궁극적으로 모노에서 유용합니다.

I suspect you will find that most modern Windows programs (with the notable exception of Notepad) handle newline-only files just fine. However, files generated with windows programs still tend to have crlf endings.

Most of the time, the line endings will automatically be handled in a platform-specific way by the runtime library. For example, a C program that opens a file with fopen(..., "r") will see the lines in a consistent way (linefeed only) on any platform regardless of the actual line endings.

As far as I know, it's only Notepad that has a problem with line separators. Virtually ever other piece of software in the world accepts any of those three types of separator, and possibility others as well. Unfortunately, Notepad is the editor of first resort for most computer users these days. I think it's extremely irresponsible of Microsoft to let this situation continue. I've never played with Vista, but I believe the problem still exists there, as it does in XP. Any body know about the next version?

As others said, there are lot of (quite trivial) converters around, should the need arise. Note that if you do the transfer with FTP in Ascii mode, it will do the conversion automatically...

Indeed, Notepad is the most proeminent program having an issue with LF ending...

The most annoying I saw is text files with mixed line ending, done essentially by people editing a Windows file on Unix, or utilities adding stuff without checking the proper format.

To be happy, just follow recommendation from the standard.

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

And offer options for special cases like old MacOS. Or handle the case automatically if you can detect them reliably.

I recommend formatting your text in Unix style. Forget about Windows users. Because no Windows users use plain-text for document or data. They will be upset if you pass plain-text. They always expect Word or Excel document. Even they use plain-text file, the only problem they will get is just weirdly displaying text.

But Unix users will experience their all tools will work incorrectly. Especially for Unix, follow the standard strictly.

PS. Oh, if your Windows user is a developer, just format with text in Unix, and tell them that's the file from Unix.

Not sure what you mean when you say 'deal' with, but basically you can just say something like:

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

  return line
}

Edit: I suspect after re-reading your question you mean how do you deal with other peoples programs that can't handle incorrect (for the target system) line breaks.

I would suggest either 1) using a program that can deal or 2) running your files through a script that finds line breaks of any type and then converts them into whatever type is right for your system.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top