View Full Version : Using the String split method
10-23-2006, 11:56 PM
I am kind of confused about the split method usage in AS3. I trying to split the data in the string using \n and \0 (null) characters but it keeps spliting them by n and zero
Null byte (escaped 0) is not allowed in String class. However, you can force 'null byte' using \x00. Of course, since AS uses null byte as termination string, you wont be able to actually use that string as display (it will show until the null byte). But you will be able to manipulate with it. E.g.:
var c_str:String = "foo\x00bar";
trace(c_str); // should trace: foo
trace(c_str.length); // should trace: 7
trace(c_str.split("\x00").join(" ")); // should trace: foo bar
Anyways, for binary operations you should use ByteArray.
As for \n (\r, \b, \t, \f, \u and \x) special characters it will certainly work. e.g.:
var c_str:String = "foo\nbar";
trace(c_str.split("\n").join(" ")); // should trace: foo bar
hope it helps...
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.