如何在ruby中打印原始字符串? [英] How to print raw string in ruby?
本文介绍了如何在ruby中打印原始字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要打印字符串的转义的或原始版本。
例如:给定以下字符串:
I want to print escaped or raw version of a string. For example: given this string:
"a,
b,
c,
d"
我想获得
"a,\nb,\nc,\nd".
有可能吗?
推荐答案
string = 'a,
b,
c,
d'
> p string.inspect
#=> "\"a,\\nb,\\nc,\\nd\""
# "*** expected output ***"
> p string.inspect.delete('\"')
#=> "a,\\nb,\\nc,\\nd"
Demo
这篇关于如何在ruby中打印原始字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文