Javascript slice by character count
Javascript slice by character count
How would one go about splitting up a block of text say 1000 characters long into 200 character segments and making each segment a div?
Re: Javascript slice by character count
You could split the string with the split method:
equivelent in php:
or with the string.substr() method:
You might want to loop it though:
Code: Select all
string.split( seperator )
Code: Select all
$array = explode( seperator, $string );
Code: Select all
string1 = string.substr(0,200)
string2 = string.substr(200,200)
string3 = string.substr(400,200);
Code: Select all
length = string.length;
loops = (length/200)
strings = []
for( var i = 0; i < loops; i++ )
{
strings[i] = string.substr( (i*200), 200 );
}
Fighting for peace is declaring war on war. If you want peace be peaceful.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Javascript slice by character count
dang you Chris you beat me to it!!!
hehe j/k
hehe j/k