[jQuery] Re: ruby style string manipulation

2007-08-01 Thread weepy
or C# style: String.prototype.$ = function() { ret = this for(i=0; i r == "hh, hello, ff"

[jQuery] Re: ruby style string manipulation

2007-08-01 Thread weepy
yes you are right i wonder if theres a clever way round this ... On Jul 27, 7:06 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > > > > From:weepy > > > > > $s = function(s) { > > > > p = s.replace(/#{/g, "' + eval(").replace(/}/g, ") + '") > > > > p = "'" + p + "'" > > > > return eval(p

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread Michael Geary
> > > From: weepy > > > > > > $s = function(s) { > > > p = s.replace(/#{/g, "' + eval(").replace(/}/g, ") + '") > > > p = "'" + p + "'" > > > return eval(p) > > > } > > > > > > a="Jonah" > > > b=30 > > > > > > $s("#{a} is #{b} years old") > > > ==> "Jonah is 30 years old" > > From: Mic

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread Mateusz Misiorny
You could also do sth like this: String.prototype.templatize = function(values) { return this.replace(/{\$([^}]+)}/g, function (full_match, group_match) { return values[group_match]; }); } and use it like this: var tpl = "Flight {$

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread Stephan Beal
On Jul 27, 7:11 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > 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? You can, to the best of my knowledge, eval

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread Michael Geary
> 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

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread weepy
another alteration to fix problems with apostrophes var $s = function(s) { p = s.replace(/'/g, '"').replace(/#{/g, "' + ").replace(/}/g, " + '"); p = "'" + p + "'"; return eval(p); } this replaces " with ' in your input string, it works best if you use " " to signify the edge of your strin

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread weepy
hehe On Jul 27, 11:36 am, David Duymelinck <[EMAIL PROTECTED]> wrote: > Can't you make it a oneliner? > > $s = function(s) { >return eval("'" + s.replace(/#{/g, "' + ").replace(/}/g, " + '") + "'"); > > } > > more place for bloated functions :) > > -- David > > weepy schreef: > > > or even >

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread David Duymelinck
Can't you make it a oneliner? $s = function(s) { return eval("'" + s.replace(/#{/g, "' + ").replace(/}/g, " + '") + "'"); } more place for bloated functions :) -- David weepy schreef: or even $s = function(s) { p = s.replace(/#{/g, "' + ").replace(/}/g, " + '") p = "'" + p + "'" ret

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread weepy
or even $s = function(s) { p = s.replace(/#{/g, "' + ").replace(/}/g, " + '") p = "'" + p + "'" return eval(p) }

[jQuery] Re: ruby style string manipulation

2007-07-27 Thread Stephan Beal
On Jul 27, 12:09 pm, weepy <[EMAIL PROTECTED]> wrote: > $s = function(s) { > p = s.replace(/#{/g, "' + eval(").replace(/}/g, ") + '") > p = "'" + p + "'" > return eval(p) > } i almost went cross-eyed matching up the ' and " chars in that s.replace() call. It's almost as readable as Perl cod