简体   繁体   中英

Get everything after first character

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!

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(":")); alert(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 Become: ":111122:123123123"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM