Javascript Substring Not Working As Expected With Long String

- 1 answer

I have a VERY long string containing code from a Rich Text Editor. I need to split this up into 4 parts to save it to the database. I am doing this.

var fullPart = $('#summernote').summernote('code').replace("'", "\'");
var markupStr = fullPart.substring(0, 3000000);
var markupStr2 = fullPart.substring(3000000, 3000000);
var markupStr3 = fullPart.substring(6000000, 3000000);
var markupStr4 = fullPart.substring(6000000);

markupStr, markupStr3 and markupStr4 all contain values, but markupStr2 is empty. What am I doing wrong?



var markupStr2 = fullPart.substring(3000000, 3000000);

Explanation : Start and End index are same in this that is why you are getting empty results.

Check here for more information.

str.substring(indexStart[, indexEnd])

indexStart The index of the first character to include in the returned substring.

indexEnd Optional. The index of the first character to exclude from the returned substring.