簡體   English   中英

獲取第一個字符后的所有內容

[英]Get everything after first character

是否可以在第一個字符之后獲取所有字符串?

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

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

謝謝!

使用indexOf(...)而不是lastIndexOf(...)

如果您想包含":"則不要在索引中添加一個。

像這樣:

 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);

只需刪除 +1,然后您的代碼就可以正常工作

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM