Split Text for Every [N] Characters

on splitText given text:someText, length:someLength
	set resultList to {}
	count someText
	
	repeat with i from 1 to result by someLength
		try
			set end of resultList to text i thru (i + someLength - 1) of someText
		on error
			-- Remaining text is shorter than someLength
			set end of resultList to text i thru -1 of someText
		end try
	end repeat
	
	return resultList
end splitText

set testText to "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse arcu nisl, consectetuer at, mollis sit amet, placerat eu, quam. Sed nulla elit, elementum non, luctus sit amet, dignissim et, magna. Aenean eu libero. In aliquam, lacus nec commodo malesuada, libero lectus lacinia sapien, ut tincidunt nulla lacus ut risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra metus." -- 400 characters
set testList to splitText given text:testText, length:160

--> {"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse arcu nisl, consectetuer at, mollis sit amet, placerat eu, quam. Sed nulla elit, elementum ", "non, luctus sit amet, dignissim et, magna. Aenean eu libero. In aliquam, lacus nec commodo malesuada, libero lectus lacinia sapien, ut tincidunt nulla lacus ut ", "risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra metus."}