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...

Reply via email to