Name
String.charAt( ) Method — retrieve the character from a specific position in a string
Availability
Flash 5
Synopsis
string.charAt(index)
Arguments
- index
The integer position of the character to retrieve, which should be in the range 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( )
; Section 4.6.5.2 in Chapter 4
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.