最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get everything after first character - Stack Overflow

programmeradmin3浏览0评论

Is it possible to get all strings after a the first character?

var val = 'asdasd:111122:123123123';
var response = val.substring(val.lastIndexOf(":")+1);

alert(response ); // "123123123"
// Would like: ":111122:123123123"

Thank you!

Is it possible to get all strings after a the first character?

var val = 'asdasd:111122:123123123';
var response = val.substring(val.lastIndexOf(":")+1);

alert(response ); // "123123123"
// Would like: ":111122:123123123"

Thank you!

Share Improve this question asked May 31, 2016 at 21:53 BriBri 5932 gold badges5 silver badges23 bronze badges 2
  • 1 try var response = val.substring(val.indexOf(":")); – blurfus Commented May 31, 2016 at 21:55
  • 2 just use indexOf rather than lastIndexOf: val.substring(val.indexOf(':')) – Hamms Commented May 31, 2016 at 21:56
Add a ment  | 

3 Answers 3

Reset to default 11

Use indexOf(...) instead of lastIndexOf(...)

If you want to include the ":" then do not add one to the index.

Like this:

var val = 'asdasd:111122:123123123';
var response = val.substring(val.indexOf(":"));

console.log(response); // ":111122:123123123"

var mobileWithCode="+91-9842505145";//mobile value with nation code

mobile = mobileWithCode.substring(mobileWithCode.indexof("-"));

alert(mobile);

Just Remove +1 And Go ahead your code will work fine

var response = val.substring(val.lastIndexOf(":"));

alert(response); // Would Bee: ":111122:123123123"
发布评论

评论列表(0)

  1. 暂无评论