Strings in ActionScript

Try each of these commands, retyping the dot each time so that you can pick from the list.

CommandOutputExplanation
trace(s.indexOf("C"));2
trace(s.length);26
trace(s.replace("BC","**"));A**DEFGHIJKLMNOPQRSTUVWXYZ
trace(s.substr(3,2));DE(substring of s beginning in 3 for a length of 2)
trace(s.substr(20));UVWXYZ(substring of s beginning in 20 for the rest of the string)
trace(s.toLowerCase());abcdefghijklmnopqrstuvwxyzlower case

The split method is used to create an array. If we type trace(s.split("")); we will see the alphabet with commas between: A,B,C,D, etc. It would usually be used to create an array: var a:Array=s.split("");
trace(a[2]); //displays C

This can be useful if we have a name as last,first:
var s:String="Banks,Robin";
var a:Array=s.split(",");
trace(a[0]); //displays Banks, a[1] is Robin

NEXT: Anagrams