// 1.截取最后一个下划线后面的数据
var account = 'hh_sa_cc_xx';
if(account.indexOf("_") == -1) {
console.log('字符串中不包含下划线');
}else {
console.log('有下划线,截取最后一个下划线后面的字段');
account = account.substring(account.lastIndexOf("_")+1)
console.log('acount', account); // 返回xx
}
// 2.截取第一个下划线后面的数据
var account1 = 'hh_sa_cc_xx';
if(account1.indexOf("_") == -1) {
console.log('字符串中不包含>');
}else {
console.log('有下划线,截取第一个下划线后面的字段');
account1 = account1.substring(account1.indexOf("_")+1)
console.log('acount1', account1); // 返回sa_cc_xx
}
js判断字符串中是否包含某个特定字符,截取特定字符前或特定字符后的数据
于 2021-11-26 19:58:06 首次发布