I have a string:
str = 'View:{
Name:"View1",
Image:{
BackgroundImage:"Image.gif",
Position: [0, 0],
Width: 320,
Height: 480
},
Button:{
BackgroundImage:"Button.gif",
Transition:"View2",
Position: [49, 80],
Width: 216,
Height: 71
},
Button:{
BackgroundImage:"Button2.gif",
Position: [65, 217],
Width: 188,
Height: 134
},'
That I use this regex to add '_#' to elements that have ':{' at the end of them
var i = 0;
str = str.replace(/([^:]+):{/g, function(m, p1) { return p1 + "_" + (++i).toString() + ":{"; });
The ouput is
str = 'View_1:{
Name:"View1",
Image_2:{
BackgroundImage:"Image.gif",
Position: [0, 0],
Width: 320,
Height: 480
},
Button_3:{
BackgroundImage:"Button.gif",
Transition:"View2",
Position: [49, 80],
Width: 216,
Height: 71
},
Button_4:{
BackgroundImage:"Button2.gif",
Position: [65, 217],
Width: 188,
Height: 134
},'
Then I do a bunch of stuff with it and now I need to strip out the '#' from it. How would I go about removing those '#'
Not cessary but another problem I am having is the the first regex is incrementing starting from 0 and giving each element the next incremented number. I am trying to make it so that each element increments on its type. Like this:
str = 'View_1:{
Name:"View1",
Image_1:{
BackgroundImage:"Image.gif",
Position: [0, 0],
Width: 320,
Height: 480
},
Button_1:{
BackgroundImage:"Button.gif",
Transition:"View2",
Position: [49, 80],
Width: 216,
Height: 71
},
Button_2:{
BackgroundImage:"Button2.gif",
Position: [65, 217],
Width: 188,
Height: 134
},'
Any input on what im doing wrong here too?