Table of Contents

String.charAt( ) Method Flash 5

retrieve the character from a specific position in a string
string.charAt(index)

Arguments

index

The integer position of the character to retrieve, which should be in the range of 0 (the first character) to string.length - 1 (the last character).

Returns

The character in the position index within string.

Description

The charAt( ) method determines the character that resides at a certain position (index) in a string.

Example

trace("It is 10:34 pm".charAt(1));  // Displays: "t" (the second letter)
var country = "Canada";
trace(country.charAt(0));           // Displays: "C" (the first letter)
   
// This function removes all the spaces from a string and returns the result
function stripSpaces (inString) {
  var outString = "";
  for (i = 0; i < inString.length; i++) {
    if (inString.charAt(i) != " ") {
      outString += inString.charAt(i);
    }
  }
  return outString;
}

See Also

String.charCodeAt( ), String.indexOf( ), String.slice( ); "The charAt( ) function," in Chapter 4


Table of Contents