[英]Ruby string escape characters
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. 我希望将下面一行中的引用字符串完全按原样输入到字符串中,但我正在绊倒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
实际上是powershell.exe的包装器,因此我想保留引号之间的所有内容,并保留已存在的转义字符。
mycommand.cmd "^|foreach-object { \"{0}=={1}\" -f $_.Name, $_.Found }"
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 \\\\
单引号中唯一的转义字符是: \\'
和\\\\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.