Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 的“替换”部分中包含变量gsub?
gsub
replace.gsub(/#{year}","1/, '#{year}","b')
这输出:
=> #{year}","b
假设年 = 2013。我希望它输出:
=> 2013","b
添加到 Blender 的答案中,您可以使用另一种编写字符串的方式来避免转义引号:
replace.gsub(/#{year}","1/, %{#{year}","b})
其中 %{} 是另一种编写字符串文字的方法,您可以在其中进行字符串插值。