gpt4 book ai didi

ruby-on-rails - 如何用\n字符替换新行

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

数据库中存储的数据是这样的:

This is a line

This is another line

How about this line

当我将它输出到 View 时,我想将其转换为:

This is a line\n\nThis is another line\n\nHow about this line

没有换行,打印出实际的 \n 字符。我该怎么做?

最佳答案

> s = "hi\nthere"
> puts s
hi
there
> puts s.gsub(/\n/, "\\n")
hi\nthere

关于ruby-on-rails - 如何用\n字符替换新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14486111/

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