Ruby heredoc 提示 Invalid escape character syntax

tablecell · May 02, 2021 · Last by vip698 replied at May 04, 2021 · 226 hits
puts  <<-STR

"c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools"
STR

提示 Invalid escape character syntax

如果对字符串内容不做转义,只是原样输出,应该怎么写

\改双写“\\”

把界位符包在单引号中即可

puts  <<'STR'

"c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools"
STR

不过你的 heredoc 中的内容为啥还要加引号?

Reply to spike76

拼路径,中间有空格的路径在命令行用不了

You need to Sign in before reply, if you don't have an account, please Sign up first.