1

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.

2 Answers 2

6

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' ....
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.