如何在不同平台上处理换行符 [英] How to deal with newline char across different platforms

查看:126
本文介绍了如何在不同平台上处理换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Linux系统,而Windows系统则互相发送文本,并且每个系统都使用接收到的文本更新文本文件,现在当文本包含LF/CR字符时我遇到了问题,我需要统一换行符由他们两个发送的char,我尝试仅使用\ n(在发送字符串之前用空字符串替换\ r),但是它不起作用,是否有针对此问题的已知解决方案?

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 ?

推荐答案

不要统一,只需像Git一样在各种环境中适应它即可.

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

从Windows发送到Linux时,将\ r \ n"CRLF"替换为\ n"LF",反之亦然,从Linux发送到Windows时,将\ n转换为\ r \ n.

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.

这篇关于如何在不同平台上处理换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆