0

Please Note: I am fully aware that this and other questions similar to it have been asked a million times, but as I have searched the Internet, I have pretty much always run into two problems in these cases:

  1. The question is something a little different, like purging all whitespace, as opposed to splitting on it.

  2. The answer given, even when accepted, is wrong. I don't understand why this point is true so much of the time here, and I agree that something's strange about this, but it is. I have tried people's "accepted" answers, on multiple occasions, and found that they have simply not been debugged at all.

So here's my question: I want to be able to take a String in AS3 and split it into an array on any and every whitespace character. Just like:

var arry:Array = ("This is a string.").split(" ");

except that I want to essentially use a wildcard character that encompasses any whitespace character. I want to use a regular expression to avoid excessive function calls and stuff like that.

How can this be done? Thanks.

4

1 回答 1

2

String.split 允许使用正则表达式分隔符。'\s' 用于空格。下面的示例产生相同的数组输出。

var arry = ("This is a string.").split(/\s/);
var arry = ("This is\ta\nstring.").split(/\s/);
于 2013-07-09T13:58:35.273 回答