javascript - Substring a part of a string using angularjs - Stack Overflow

I have a string like this string(1), I want to get substring remove the last part to obtain just string

I have a string like this string(1), I want to get substring remove the last part to obtain just string any suggestions please!!

PS.the string could be: sringggg(125).

I have a string like this string(1), I want to get substring remove the last part to obtain just string any suggestions please!!

PS.the string could be: sringggg(125).

Share Improve this question edited Dec 14, 2016 at 8:58 Ivan Chaer 7,0901 gold badge40 silver badges49 bronze badges asked Dec 14, 2016 at 8:12 user7035864user7035864 0
Add a ment  | 

3 Answers 3

Reset to default 3

You can use various options to get the desired string.

//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('(')));

References

  • String.prototype.split()
  • String.prototype.indexOf()

If string is always in same pattern and ' ( ' is a separator use split .

var string =  'string(1)'
var result = string .split('(')[0];

Try using regexp

var tesst = "string(1)"
var test = tesst.match(/^[^\(]+/);
// test = "string"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745112465a4611926.html

相关推荐

  • javascript - Substring a part of a string using angularjs - Stack Overflow

    I have a string like this string(1), I want to get substring remove the last part to obtain just string

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信