Search code examples
cross-platformnewlinecommunicationtext-editor

How to deal with newline char across different platforms


I have a Linux system and Windows system send text to each other and each one of them update a text file with the received text, now i have a problem when the text contain LF/CR char, i need to unify the newline char sent by both of them, i tried to use only \n (replacing \r by empty string before sending the string) but it doesn't work , is there a known solution for this issue ?


Solution

  • Don't unifying, just accommodate for it in every environment, like Git does.

    When sending from Windows to Linux replace \r\n "CRLF" with \n "LF" and vice versa, when sending from Linux to Windows convert \n to \r\n.