0

I have a string like this:

var str = "T  h  i  s     i  s     a              t  e  s  t";
//         1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17

Now I want to remove this range: [11 - 13], And I want this output:

var newstr = "T  h  i  s     i  s     a     t  e  s  t";
//            1  2  3  4  5  6  7  8  9  10 14 15 16 17

How can I do that?

Shafizadeh
  • 9,960
  • 12
  • 52
  • 89
  • 2
    You want to replace multiply whitespaces with one? `str.replace(/\s+/g, '');` – Andreas Louv Jan 31 '16 at 03:10
  • 1
    This might be a replica of: http://stackoverflow.com/questions/1981349/regex-to-replace-multiple-spaces-with-a-single-space – Mfbaer Jan 31 '16 at 03:12
  • 1
    The solution by @dev-null is better to remove multiple spaces, however I'd like to correct it. Replace one or more space by a single space. `.replace(/\s+/g, ' ')` // Note, second argument, a space – Tushar Jan 31 '16 at 06:06
  • @Tushar Thanks for the correction, just a typo from my side. – Andreas Louv Feb 01 '16 at 06:57

1 Answers1

2

This should do it:

var newstr = str.slice(0, 10) + str.slice(14);
Dan Ovidiu Boncut
  • 3,083
  • 4
  • 25
  • 45