Reputation: 108
How do you convert a string into a char array in ActionScript 3.0?
I tried the below code but I get an error:
var temp:ByteArray = new ByteArray();
temp = input.toCharArray();
From the error, I understand that the toCharArray() function cannot be applied to a string (i.e in my case - input). Please help me out. I am a beginner.
Upvotes: 1
Views: 7737
Reputation: 757
Depending on what you need to do with it, the individual characters can also be accessed with string.charAt(index), without splitting them into an array.
Upvotes: 0
Reputation: 49352
I am not sure if this helps your purpose but you can use String#split():
If you use an empty string ("") as a delimiter, each character in the string is placed as an element in the array.
var array:Array = "split".split("");
Now you can get individual elements using index
array[0] == 's' ; array[1] == 'p' ....
Upvotes: 6