ruby - ruby on rails 用双引号替换字符串中的单引号
问题描述
我正在尝试用字符串中的双引号替换单引号,如下所示:
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 的不同方法,但到目前为止没有任何效果。有任何想法吗?
解决方案
如果这是您要覆盖的唯一情况,那么您需要在双引号字符串中显示一些输出。像下面这样简单的东西怎么样
str = "The result of the child is \"#{current_res}\" and the lowest grade is \"#{lowest_res }\" ."
您可以在双引号字符串中转义引号。
推荐阅读
- java - 将 mp3 文件中的字节表示为十六进制字符串
- excel - MS Excel If 语句不适用于班次公式?
- django - 我什么时候需要 staticfiles_urlpatterns
- kendo-ui - 如何更改 kendo ui 圆环图系列 categoryField 中的数据排序?
- apache-flink - Flink 如何将 DAG 节点分配到不同的任务槽?
- telerik - Telerik UI 用于 UWP RadCalendar 控件绑定到选定日期
- python - 生成 Twilio Python 客户端功能令牌
- azure-storage - 如何使用 nifi 从文件共享位置获取文件?
- jenkins - 如何将从节点上的 .jenkins 文件夹路径更改为另一个目录值
- livecode - 如何在实时代码中包含库文件(.dll/.lib)并使用库文件中的函数