我有一个像这样的字符串string(1)
,我想要子字符串删除最后一部分以获得string
请任何建议!!
PS。字符串可以是:sringggg(125)
。
最佳答案
您可以使用各种选项来获取所需的字符串。
//With regular expression with split() and fetch the first element of array
console.log('sringggg(125)'.split(/\(\d+\)/)[0]);
//Using string with split() and fetch the first element of array
console.log('sringggg(125)'.split('(')[0]);
//Using substr and indexOf
var str = 'sringggg(125)'
console.log(str.substr(0, str.indexOf('(')));
引用文献
关于javascript - 使用 angularjs 对字符串的一部分进行子串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41137702/