1.字符方法 1.1 charAt() 方法,返回字符串中指定位置的字符. var question = "Do you like JavaScript?"; alert(question.charAt(5)); //"u" 字符串 "Do you like JavaScript?" 的长度为23,即位置从0到22.指定位置5处的字符是"u". 1.2 charCodeAt() 方法,返回字符串中指定位置的字符编码. var
charAt() 方法用于返回指定索引处的字符.索引范围为从 0 到 length() - 1. 参数 index -- 字符的索引. 返回值 返回指定索引处的字符. 实例 public class Test { public static void main(String args[]) { String s = "www.runoob.com"; char result = s.charAt(8); System.out.println(result); } }