Advertise with us

How to split the string in to different parts

Hi Everyone! 

I want to split the string in to different parts. I will have some string which will be generated dynamically which will contains 500 characters. I want to split in to 5 parts. What i mean is i want to take 100 characters in to array[0], next 100 characters in array[1] ....

Example:

 var string = "kjfaorj.......................................................";
 array[0] = "kjfaorj..... up to 100 characters";
 array[1] = " next 100 characters ";

Thanks in advance! 
Last updated:5/15/2013 8:44:47 AM

1 Answers

AVADHESH PATEL
AVADHESH PATEL

Hi Manoj!


if(str.length % 100 == 0) //If the string contains exactly 500 or 400...etc
     count = str.length / 100;
  else
    count = str.length / 100 +1; //If the string contains exactly 505 or 417...etc

for(var i=0;i<count;i++)
  array[i] = s.substring(i,i*100-1);

Second approach is good for dynamic string

Thanks in advance! 

Answer