jquery - Get substring between 2 certain characters -
for example have string:
via_route_1;via_route_2;via_route_4;via_route_7;
and supply function number (eg. 4), how can substring ;via_route_4
?
my aim delete substring, depending on number supply.
i know how index of 4, example, how go backwards until find first ;
, take whole substring thing?
what that? using no custom functions manipulating string.
/* string */ var s = "via_route_1;via_route_2;via_route_4;via_route_7;"; /* index of 4 */ var i1 = s.indexof("4"); /* substring first character 4 (including number) */ var sub1 = s.substring(1, i1 + 1); /* last index of ; in substring */ var i2 = sub1.lastindexof(";"); /* new substring starting ; */ var sub2 = sub1.substring(i2, sub1.length); console.log(sub2);
logs ;via_route_4
.
Comments
Post a Comment