I have a long url route and I only need to increment a section of the route. Right code to increment this is very crude looking and seems buggy. I'm currently using regex in javascript, but maybe that too complicated:
/superbowl-XIX-group01-01/offense/11
I want to increment the group # route to this using javascript:
/superbowl-XIX-group02-01/offense/11
And I'm currently using this code:
var nextRosterStr = "";
nextRosterStr = $('#btnShowMore').attr("next-page");
if (typeof nextRosterStr === 'undefined') {
return;
} else if (isUIButton === false) {
// update the btnShowMore attribute as well
var gNumberValue = nextRosterStr.match(/-group0?\d*-/g);
gNumberValue = gNumberValue.toString().replace(/0/, "ZERO");
var gNumberStr = gNumberValue.toString().match(/\d*/g);
var gNumber = parseInt(gNumberStr.join(""), 10);
gNumber++;
var gNumberValueFinal = "";
if (gNumber > 9) {
gNumberValueFinal = gNumberValue.replace(/\d*/g, gNumber.toString(10));
gNumberValueFinal = gNumberValueFinal.toString().replace("ZERO", "").toString();
} else {
gNumberValueFinal = gNumberValue.toString().replace(/\d+/g, gNumber.toString(10));
gNumberValueFinal = gNumberValueFinal.toString().replace("ZERO", "0").toString();
}
var nextRosterStr = nextRosterStr.replace(/-group0?\d*-/g, gNumberValueFinal.toString());
btw here is a route setup example:
new RouteMappingItem()
{
PageName = "Superbowls",
Url = "/{GameType}-{GameIdentifier}-group{groupNumber}-01/{formationName}/{rankingCount}",
Defaults = new { controller = ...
},
There has got to be a simpler way to do this.