我已经尝试过gsub(“ [\ r \ n] +”,“ \ r \ n”,textDoc),但是它似乎将\ r和\ n单独对待,而不是作为单个字符串来对待?
编辑 -
"This is a line! It ends with a CRLF!\r\n
\r\n
\r\n
There is more stuff down here! I want it directly below the other stuff! Get rid of those two blank lines! Actually, ANYTIME I have blank lines, lets remove them!\r\n"
[\r\n]+
与一起使用char类[]
。这就是char类的工作方式。
您想要()
一个捕获组:(\r\n)+
编辑:
实施此操作存在一些问题,因为它正在插入额外的\r
。
经过多次评论,我猜想替换应该是just \n
,并且添加了一个\r\n
(按预期)。
我不确定为什么会发生这种情况,但我认为为了确保跨系统兼容性,请\n
映射到\r\n
,从而\r\n
映射到\r\r\n
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句