问题
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 }"
回答1:
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 \\
来源:https://stackoverflow.com/questions/11270944/ruby-string-escape-characters