Ruby字符串转义字符 [英] Ruby string escape characters
本文介绍了Ruby字符串转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将下面的引用字符串完全按照原样获取到字符串中,但是我正在跳过Ruby所需的转义序列。 mycommand.cmd
真的是powershell.exe的包装器,所以我想保留引号之间的所有内容,并且保持已经存在的转义字符。
I want to get the quoted string in the line below into a string exactly as-is, but I am tripping on the necessary escape sequences for Ruby. mycommand.cmd
is really a wrapper for powershell.exe so I want to preserve everything between the quotes, and hold onto the escape characters that are already there.
mycommand.cmd "^|foreach-object { \"{0}=={1}\" -f $_.Name, $_.Found }"
推荐答案
使用单引号: / p>
Use single quotes :
ruby-1.9.3-p0 :001 > '^|foreach-object { \"{0}=={1}\" -f $.Name, $.Found }'
=> "^|foreach-object { \\\"{0}=={1}\\\" -f $.Name, $.Found }"
单引号中唯一的转义字符是: \'
和 \\
The only escape characters in single quotes are : \'
and \\
这篇关于Ruby字符串转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文