开发者

Single quoted Ruby strings -- inconsistent escaping

开发者 https://www.devze.com 2023-01-08 01:05 出处:网络
Why do the following strings give me the same output in the Ruby interpreter? \'f:\\new\' \'f:\\\\new\'

Why do the following strings give me the same output in the Ruby interpreter?

  'f:\new'
  'f:\\new'

Both strings result in: "f:\\new". I was expecting the second string to display "f:\\\\new开发者_如何转开发" (if not that, then the first one should have shown "f:\new")


Single-quoted strings support only two escape sequences: \' and \\

That's why in your first example \n is not treated as new-line char: it's not in the list.

0

精彩评论

暂无评论...
验证码 换一张
取 消