cut out part of a string

前端 未结 8 1556
北荒
北荒 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 17:02

    You're almost there. What you want is:

    http://www.w3schools.com/jsref/jsref_substr.asp

    So, in your example:

    Var string = "hello is it me you're looking for";
    s = string.substr(3);
    

    As only providing a start (the first arg) takes from that index to the end of the string.

    Update, how about something like:

    function cut(str, cutStart, cutEnd){
      return str.substr(0,cutStart) + str.substr(cutEnd+1);
    }
    

提交回复
热议问题