从红宝石的字符串中跳出单和双qoutes [英] Escaping single and double qoutes from a string in ruby
本文介绍了从红宝石的字符串中跳出单和双qoutes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从字符串中转义单引号和双引号?
How can I escape single and double quotes from a string?
我想一起转义单引号和双引号。我知道如何分开通过,但不知道如何通过他们。
I want to escape single and double quotes together. I know how to pass them separately but don't know how to pass both of them.
例如: str =ruby'on rails = ruby'on rails
推荐答案
我的首选方法是不用担心转义使用%q(其行为类似单引号字符串)或%Q表示双引号字符串行为。
My preferred way is to not worry about the escaping and using %q (which acts like a single quoted string) or %Q for double quoted string behavior.
so
str = %q[ruby 'on rails"] # Single quoting
str2 = %Q[quoting with #{str}] # will insert variable
这篇关于从红宝石的字符串中跳出单和双qoutes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文