dimanche 22 novembre 2015

How to parse number from middle of string

I need to parse some numbers from a string, I can get the last number easily but wonder how to get the number mid string reliably. In this case the number 12?

var mystring = 'group 999999999 group-session-info 12 of 50';
var i;
var num; //how to get num "12"
var numOf;
i= mystring.lastIndexOf(" ");
if (i != -1) {
   numOf= mystring.substr(i);
}
alert(numOf); // = 50

Thanks

Aucun commentaire:

Enregistrer un commentaire