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どの時点でも 2 つのバックスラッシュが含まれていないためです。a次の 5 文字で構成されます。
a
\
r
n
p
pry に検査を依頼すると、\リテラルごとにエスケープ文字を表示する必要があり\ます。走れputs aば見えるはず\r\np
puts a
\r\np
キャリッジ リターンと改行の制御コードを含むように文字列を編集する場合は、次のようにする必要があります。
a.gsub('\\r', "\r").gsub('\\n', "\n")