cut out part of a string

前端 未结 8 1580
北荒
北荒 2021-02-18 16:17

Say, I have a string

\"hello is it me you\'re looking for\"

I want to cut part of this string out and return the new string, something like

8条回答
  •  死守一世寂寞
    2021-02-18 16:50

    s = string.cut(5,7);
    

    I'd prefer to do it as a separate function, but if you really want to be able to call it directly on a String from the prototype:

    String.prototype.cut= function(i0, i1) {
        return this.substring(0, i0)+this.substring(i1);
    }
    

提交回复
热议问题