我試圖用字串中的雙引號替換單引號,如下所示:
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 嘗試了不同的方法,但到目前為止沒有任何效果。有任何想法嗎?
uj5u.com熱心網友回復:
如果這是您需要在雙引號字串中顯示某些輸出的唯一情況。像下面這樣簡單的事情怎么樣
str = "The result of the child is \"#{current_res}\" and the lowest grade is \"#{lowest_res }\" ."
您可以在雙引號字串中轉義引號。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360006.html
上一篇:有沒有辦法撰寫一個匹配除檔案夾中的檔案之外的所有檔案的glob模式?
下一篇:Ruby如何格式化嵌套哈希
