Skill Sets:


  1. Intro to Flash
  2. User Input
  3. Fancy Controls 1
  4. Control Flow: if
  5. Control Flow: loop
  6. Nested Structures
  7. Graphics 1
  8. Arrays
  9. Strings
  10. Mouse Movement
  11. Functions
  12. Grouping Images
  13. Graphical Support
  14. Animation
  15. Physics
  16. 2010 Grade 10 Summative showcase
  17. 2010 Grade 11 Summatives
  18. 2011 Grade 10 Summatives
  19. 2011 Grade 11/12 Summatives
  20. Sept 2011 Grade 11 Summatives
  21. Sept 2011 Grade 10 Summatives
  22. Feb 2012 Grade 10 Summatives
  23. Sept 2012 Summatives
  24. Feb 2013 Grade 12 Summatives
  25. Feb 2013 2OI Summatives
  26. Sept 2013 Summatives


Strings are a character array in disguise. Learning this will allow you to grab individual letters from words with ease.

Lots of contest problems are rooted in your ability to assess individual characters in sentences. Also in this Skill Set, you will be introduced to file i/o: input and output. This will allow you to get information from an external text file. All programming contests are rooted in reading standard information from a text file, so it will be included in this skill set.

We can go back to Skill Set 2: user input with an External File. Back then, we asked the user for their name, and then we outputted a greeting.

We populated the sName variable from an Input TextField by way of:

sName = txtName.text;   
That was within the EventListener.

The String Class has many functions that are available to you. For example, once sName is populated, you can:

trace (sName.length); // this will output the size of the String.

The following code displays each letter in sName as well as the ASCII value:

for (var i:int = 0; i < sName.length; i++)
   trace(sName.charAt(i), "-", sName.charCodeAt(i));

You can turn numbers into Strings:

var nNum:Number = 23.57;  
var str:sNum = nNum.toString();  

You can "concatenate" Strings (combine them):

sFullName = sFirst + sLast;

You can "Slice" up a String:

trace (sName.slice(-2,sName.length));

The first example gets a "subString" of the String, and gets the chars starting with the first letter (index 0), and up to, but not including the char at index 2.

The slice function grabs the char second from the end up to but not including the index of the lenght. Since Strings start at index 0, the index of the length of the array is one bigger than the array itself.

Finding chars within a String:

sSentence = "The cake is a lie"; 
trace(sSentence.indexOf("is")); // output: 9

Notice that the indexOf() method is case-sensitive.

You can specify a second parameter to indicate the index position in the string from which to start the search, as follows:

trace(sSentence.indexOf("e",2)); // output: 2
trace(sSentence.indexOf("e",3)); // output: 7

In the first example, since there is an "e" at index 2, 2 is outputted. In the second example, the next occurence of "e" after index 3 is 7.

The value of -1 will be returned if no occurence can be found.

The lastIndexOf() method finds the last occurrence of a substring in the string.

Other String Methods







Returns the character at the position (pos).



Returns the character code of the character at the position (pos).



Returns the character from the character code number (num).



Returns the location of the inner string in the main string.



Replaces the pattern within the string.



Returns the substring starting at position (start) and ending at position (end).



Converts a number or other value to a string.



Returns the substring starting at position (start) of length (len).



Returns the string with lower case letters.



Returns the string with upper case letters.



Returns a new string with the second string appended to end of the first string.



Returns the number of characters in the string.


There's more at adobe's site.