标签: ruby string casting
如何进行以下字符串转换:
"ln(5*x)" -> "Math.log(5*x)"
答案 0 :(得分:2)
"ln(5*x)".sub('ln','Math.log') #=> "Math.log(5*x)"
答案 1 :(得分:0)
"math.log(#{"ln(5*x)"[/ln\((.*)\)/,1]})"