Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  74] [ 6]  / answers: 1 / hits: 92086  / 15 Years ago, tue, november 10, 2009, 12:00:00

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



s = string.cut(0,3);


s would now be equal to:



lo is it me you're looking for


EDIT: It may not be from 0 to 3. It could be from 5 to 7.



s = string.cut(5,7);


would return



hellos it me you're looking for

More From » string

 Answers
73

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);
}

[#98344] Friday, November 6, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
xavier

Total Points: 711
Total Questions: 91
Total Answers: 121

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
xavier questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sat, Sep 26, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Sat, Oct 12, 19, 00:00, 5 Years ago
;