May 2001
Intermediate to advanced
720 pages
23h 24m
English
String.charAt( ) Method — retrieve the character from a specific position in a string
Flash 5
string.charAt(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).
The character in the position index within
string.
The charAt( ) method determines the character
that resides at a certain position (index)
in a string.
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;
}
String.charCodeAt( ), String.indexOf(
), String.slice( ); Section 4.6.5.2 in Chapter 4
Read now
Unlock full access