gpt4 book ai didi

ruby-on-rails - 给定一个字符串,如何附加一个回车符后跟另一个字符串?

转载 作者:数据小太阳 更新时间:2023-10-29 07:20:16 25 4
gpt4 key购买 nike

我有一个像这样的字符串 string1:

Hello World, join my game:

我想让 string1 变成:

Hello World, join my game:

http://game.com/url

如何使用 ruby​​ 附加一个回车符,然后附加一个来自另一个变量的链接?

谢谢

最佳答案

这实际上取决于您要输出的内容。

$标准输出:

puts "Hello\n\n#{myURL}"

puts "Hello"
puts
puts myURL

puts <<EOF
Hello

#{myURL}
EOF

如果您在 html.erb 中输出它或 .rhtml文档:

<%= "Hello<br /><br />#{myURL}" %> # or link_to helper

如果你已经有一个类似 string1 的字符串然后您可以使用 += 附加到它或 << :

string1  = "Hello world, join my game:"
myUrl = "http://example.com"
string1 += "\n\n#{myUrl}"

或:

string1 = "Hello world, join my game:"
myUrl = "http://example.com"
string +=<<EOF

#{myUrl}
Here's some other details
EOF

关于ruby-on-rails - 给定一个字符串,如何附加一个回车符后跟另一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10033452/

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