【发布时间】:2021-12-22 09:53:31
【问题描述】:
我正在尝试用字符串中的双引号替换单引号,如下所示:
current_res = 25
lowest_res = 15
str = "The result of the child is '#{current_res}' and the lowest grade is '#{lowest_res }'."
我需要输出看起来像:
str = The result of the child is "25" and the lowest grade is "15".
我尝试了使用 gsub 的不同方法,但到目前为止没有任何效果。有什么想法吗?
【问题讨论】:
-
我刚跑了
puts str.gsub(/'/, '"')你想分享你使用的gsub调用吗?你能澄清你想要的输出吗?那应该是红宝石还是文字字符串输出? (如果是前者,那不是有效的 ruby 代码;如果是后者,你打算运行什么命令以在开头给你str =?
标签: ruby string escaping double-quotes single-quotes