...

View Full Version : String



tuxcoder
02-02-2007, 12:25 PM
Hello

I have this string:
var Aussage = '{"48":["day":4]}{"49":[ "day":4]}';

Whit indexOf i search the Position for the String 48
var Suche = Aussage.indexOf("48");


Now i want search the char { from the left of 48 and } from the right and delete all chars between.

How can i do this??

liorean
02-02-2007, 02:58 PM
You can do it with a regex without indexOf, like this:
var
re=/\{(['"]?)48\1:[^}]*\}/g,
sOrig='{"48":["day":4]}{"49":[ "day":4]}',
sNew=sOrig.replace(re,'');However, this does not work if you have nested "}" that you don't want to match.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum