How can i remove from a string between two indexOf
i have this jsFiddle
here is my code :
var x = "M 178.6491699876038 23.419570090792845 C 183.6491699876038
23.419570090792845 186.47776067057902 30.902823043098138 190.3670728596699
41.19229585251793 L 194.25638504876076 51.48176866193772" ;
var c = x.indexOf('C') ;
var L = x.indexOf('L') ;
var final = x.slice (c,L) ;
console.log(final) ;
this code will result in returning the removed part of the string
QUESTION how can i return the original string after removing the part between C
and L
How can i remove from a string between two indexOf
i have this jsFiddle
here is my code :
var x = "M 178.6491699876038 23.419570090792845 C 183.6491699876038
23.419570090792845 186.47776067057902 30.902823043098138 190.3670728596699
41.19229585251793 L 194.25638504876076 51.48176866193772" ;
var c = x.indexOf('C') ;
var L = x.indexOf('L') ;
var final = x.slice (c,L) ;
console.log(final) ;
this code will result in returning the removed part of the string
QUESTION how can i return the original string after removing the part between C
and L
Share Improve this question asked Jul 19, 2012 at 17:48 Mina GabrielMina Gabriel 25.1k26 gold badges99 silver badges128 bronze badges 3- 1 whats wrong with just using X? – Limey Commented Jul 19, 2012 at 17:52
- what do you mean by using x ?????????????????????????????? – Mina Gabriel Commented Jul 20, 2012 at 0:49
- 1 Nevermind, from your wording, I thought you just wanted your oringinal string, which would of been in X, not your orginal string minus the middle. – Limey Commented Jul 20, 2012 at 12:06
5 Answers
Reset to default 9var c = x.indexOf('C') ;
var L = x.indexOf('L') ;
var remaining = x.slice(0, c) + x.slice(L);
Fiddle:
http://jsfiddle/ePbCP/
Just replace that part of the original string with nothing :
var x = "M 178.6491699876038 23.419570090792845 C 183.6491699876038 23.419570090792845 186.47776067057902 30.902823043098138 190.3670728596699 41.19229585251793 L 194.25638504876076 51.48176866193772" ;
var c = x.indexOf('C') ;
var L = x.indexOf('L') ;
var final = x.slice (c,L) ;
console.log(x.replace(final, ''));
FIDDLE
You can use 2 substring
s for this.
var c = x.indexOf('C') ;
var L = x.indexOf('L') ;
var y = x.substring(0, c) + x.substring(L);
Try:
var x = "M 178.6491699876038 23.419570090792845 C 183.6491699876038 23.419570090792845 186.47776067057902 30.902823043098138 190.3670728596699 41.19229585251793 L 194.25638504876076 51.48176866193772";
var c = x.indexOf('C');
var L = x.indexOf('L');
var final = x.substring(0, c) + x.substring(L, x.length);
console.log(final);
You can replace the final string with empty string to get the remaining part.
var remaining = x.replace(final,'');
Live Demo