在javascript字符串中的破折号后获取所有内容 [英] Get everything after the dash in a string in javascript

查看:56
本文介绍了在javascript字符串中的破折号后获取所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE和firefox中都可以使用的最干净的方法是什么.

What would be the cleanest way of doing this that would work in both IE and firefox.

我的字符串如下:sometext-20202

My string looks like this: sometext-20202

现在,"sometext"和破折号后的整数可以具有不同的长度.

Now the 'sometext' and the integer after the dash can be of varying length.

我应该只使用的子字符串和索引还是其他方式?

Should I just use substring and index of or is the other ways?

推荐答案

我该怎么做:

// function you can use:
function getSecondPart(str) {
    return str.split('-')[1];
}
// use the function:
alert(getSecondPart("sometext-20202"));

这篇关于在javascript字符串中的破折号后获取所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆