请问 Ruby 中与 Python 字符串的 encode('string_escape')
和 decode
函数 等价的函数是什么?
在 Python 中,我可以这样做:
>>> s="this isn't a \"very\" good example!"
>>> print s
this isn't a "very" good example!
>>> s
'this isn\'t a "very" good example!'
>>> e=s.encode('string_escape')
>>> print e
this isn\'t a "very" good example!
>>> e
'this isn\\\'t a "very" good example!'
>>> d=e.decode('string_escape')
>>> print d
this isn't a "very" good example!
>>> d
'this isn\'t a "very" good example!'
如何在Ruby中实现相同的功能?
string.gsub(/\\"/, '"')
可能吗?这太琐碎了,实际上没有任何内置方法。 - tadmaneval()
来获取JSON编码数据?我也不希望出现不可打印的二进制,但几乎可以接受任何其他类型的数据。 - FriendFXeval
和/或gsub
解决方案结合起来,为我提供一个完整的答案,包括解码,这样我就可以接受了? - FriendFXeval
绝对不是你想要的东西。 - tadman