开发者

piece of string

Hy guys

I 开发者_StackOverflow社区have a string containing:

'09:29'

. How can I return the

'29'

and eliminate the '09:'?

Thks!


You can .split() the string into an array and .pop() the result (last member) pretty cleanly, like this:

var str = '09:29';
return str.split(':').pop();

You can test it out here.


var str = '09:29';
var parts = str.split(':');
alert(parts[1]);


An alternative is to use Regular expressions (see this demo). I believe this code should do the trick (not tested).

var re = new RegExp("\b\d+:(\d+)\b");
var m = re.exec(yourString);
if(m !=  null) {
     alert("Match: "+ m[1]);
}


regex version:

return /\d{2}\:(\d{2})/.exec('09:29')[1];


   var time = "09:29"
   var bits = time.split(":")
   var minutes = bits[1]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜