I’m trying to split all the words in a string into an array in AS3. The obvious answer of course would be to simply do this:
str.split(/\s/);
The problem here is that I need to be able to tell whether the split occurred on a newline or a space. I’m trying to put the words of a string into draggable boxes, and I want the ones after a newline to go, well, on a new line.
Any idea the best way to go about this? Clearly, the above split method will get rid of the crucial newline character that will tell me what I need to know. Should I use a regex.exec with a while loop, or is there any way to use split to preserve the characters I need?
Example string :
1/ Split the string on newline, get array#1.
2/ For each element in array#1 , split based on your current regex which will break the strings
only on spaces as newlines have already been dealth with, this 2-D array is array#2
3/ Process elements of array#2 as you want.