gpt4 book ai didi

像 PHP nowdoc 这样的 Ruby 多行字符串?

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:23 26 4
gpt4 key购买 nike

在 Ruby 中可以像 PHP 的 nowdoc [1] 那样使用多行字符串

例如

puts '

\\foo

'

我想输出如下没有转义的

\\foo

[1] Nowdocs 之于单引号字符串就像 heredocs 之于双引号字符串。 nowdoc 的指定类似于 heredoc,但在 nowdoc 内部不进行任何解析。 http://hk1.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc

最佳答案

literals documentation 中所述,您只需要在 heredoc 标识符周围加上单引号,如下所示:

puts <<'EOS'
#{variable}
\\escaped
EOS

输出:

#{variable}
\\escaped

关于像 PHP nowdoc 这样的 Ruby 多行字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21991797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com