在javascript中,有一个charAt函数,可以参考它。
------------------------------------------------------------
charAt method
Returns the character at the specified index.
语法
stringName.charAt(index)
stringName is any string or a property of an existing object.
index is any integer from 0 to stringName.length - 1, or a property of an existing object.
用法
string
描述
Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is stringName.length - 1. If the index you supply is out of range, javascript returns an empty string.
例子
The following example displays characters at different locations in the string "Brave new world".
var anyString="Brave new world"
document.write("The character at index 0 is " + anyString.charAt(0))
document.write("The character at index 1 is " + anyString.charAt(1))
document.write("The character at index 2 is " + anyString.charAt(2))
document.write("The character at index 3 is " + anyString.charAt(3))
document.write("The character at index 4 is " + anyString.charAt(4))
See also
indexOf, lastIndexOf methods