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
year = 2013としましょう。出力したい:
=> 2013","b
Blender の回答に加えて、文字列を記述する別の方法を使用して、引用符をエスケープする必要がないようにすることができます。
replace.gsub(/#{year}","1/, %{#{year}","b})
%{} は、文字列補間を実行できる文字列リテラルを記述する別の方法です。
鬼ごっこ