Friday, October 2, 2009

[jQuery] Re: how to replace all the '[]' to be '' in $.SortSerialize('MDEExportedList').hash

Thanks for all replies.
 
i use replace(new RegExp(".\]","g")  to get it work.
 
Thanks.

On Fri, Oct 2, 2009 at 10:31 AM, Karl Swedberg <karl@englishrules.com> wrote:


On Oct 1, 2009, at 5:34 PM, waseem sabjee wrote:

heres an interesting way of doing

var x = mystring.length;
for(x; x > 0; x--) {
 var s = mystring[x];
// if this character is an instance of the character you want to replace
if(mystring.match(/[]/)
 // replace it
 mystring.replace(/[]/, "replacement");
}

It might be interesting, but it seems like a lot of extra work. This can be done with a simple regex replace, as someone already mentioned:

var newString = $.SortSerialize('MDEExportedList').hash.replace(/\[|\]/g,'');

Not sure what $.SortSerialize('MDEExportedList').hash is all about, but the replace() function should work.


--Karl

____________
Karl Swedberg


No comments: