> From: weepy > > Sick and tired of string manipulation in javascript ? I was.... > > Try this nice little function : > > $s = function(s) { > p = s.replace(/#{/g, "' + eval(").replace(/}/g, ") + '") > p = "'" + p + "'" > return eval(p) > } > > OK it's not exactly bullet-proof, but it's the concept that > counts here. > > So now you can do : > > a="Jonah" > b=30 > > $s("#{a} is #{b} years old") > ==> "Jonah is 30 years old" > > Obviously any stray '#{' and '}' sequences will break it...
Sorry to be a party pooper, but what happens if you call $s from inside a function, using replacement variables that are local to that function? How will the "eval" see those variables? -Mike