Actionscript2: Split string by line length with & without word-wrap
Split string into sentences by max line length.
This uses a character array but doesn’t use word-wrapping.
_root.myArray = new Array();
_root.myArray = personalMessage.split("");
_root.mySentences = new Array();
var currentCharCount:Number = 0;
var currentCharItem:Number = 0;
var currentCharString:String = "";
var maxLength:Number = 65;
for (var i=0; i<_root.myArray.length; i++ ) {
if (currentCharCount<maxLength) currentCharString += _root.myArray[i];
if (currentCharCount==maxLength || currentCharItem==(_root.myArray.length-1)) {
_root.mySentences.push(currentCharString);
currentCharCount = 0;
currentCharString = "";
}
currentCharCount++;
currentCharItem++;
}
trace(_root.mySentences.length);
trace(_root.mySentences[0]);
trace(_root.mySentences[1]);
trace(_root.mySentences[2]);
This outputs the following:
You got this far so we reckon that you could be curious enough to
learn a little more, we’ll contact you shortly to answer any que
tions you may have.
Split string into sentences by max line length and use word-wrapping.
_root.myArray = new Array();
_root.myArray = personalMessage.split(" ");
_root.mySentences = new Array();
var currentCharString:String = "";
var maxLength:Number = 60;
for (var i=0; i<_root.myArray.length; i++ ) {
if (currentCharString.length<maxLength) currentCharString += _root.myArray[i] + " ";
if ((currentCharString.length >= (maxLength-1)) || (i==(_root.myArray.length-1))) {
_root.mySentences.push(currentCharString);
currentCharString = "";
} else currentCharCount++;
}
trace(_root.mySentences.length);
trace(_root.mySentences[0]);
trace(_root.mySentences[1]);
trace(_root.mySentences[2]);
This outputs the following:
You got this far so we reckon that you could be curious enough
to learn a little more, we’ll contact you shortly to answer
any questions you may have.
Trackbacks
There are no trackbacks on this entry.

Comments
There are no comments on this entry.