Created
September 16, 2014 20:35
-
-
Save b4blue/819439b100568a683cb5 to your computer and use it in GitHub Desktop.
Split sentence into smaller chunks and separate lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private function breakSentence(str:String, maxLength:int):String { | |
| var finalString:String = ""; | |
| if (str.length > maxLength) { | |
| var str_array:Array = str.split(" "); | |
| var sum:int = 0; | |
| for (var n:int = 0; n < str_array.length; n++) { | |
| sum += str_array[n].length + 1; | |
| if (sum > maxLength) { | |
| n--; | |
| sum = 0; | |
| finalString += "\n"; | |
| } else { | |
| finalString += str_array[n] + " "; | |
| } | |
| } | |
| } else { | |
| finalString = str; | |
| } | |
| return finalString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment