Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
[28] pry(main)> a => "\\r\\np" [30] pry(main)> a.gsub('\\\\','\\') => "\\r\\np"
它应该返回:
"\r\np"
..或者至少我希望它返回那个..
因为a在任何时候都不包含两个反斜杠。a由以下五个字符组成:
a
\
r
n
p
当您要求 pry 检查它时,它必须显示\每个文字的转义字符\;如果你跑puts a,你应该看到\r\np
puts a
\r\np
如果要编辑字符串以包含回车和换行的控制代码,您可能需要:
a.gsub('\\r', "\r").gsub('\\n', "\n")