Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  100] [ 5]  / answers: 1 / hits: 39084  / 14 Years ago, mon, march 7, 2011, 12:00:00

i have the following:



var S=hi how are you;
var bindex = 2;
var eindex = 6;


how can i remove all the chars from S that reside between bindex and eindex?

therefore S will be hi are you


More From » javascript

 Answers
10

First find the substring of the string to replace, then replace the first occurrence of that string with the empty string.



S = S.replace(S.substring(bindex, eindex), );


Another way is to convert the string to an array, splice out the unwanted part and convert to string again.



var result = S.split('');
result.splice(bindex, eindex - bindex);
S = result.join('');

[#93399] Friday, March 4, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madalyngriseldas

Total Points: 167
Total Questions: 92
Total Answers: 85

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;