@[TOC](JAVA/JAVASCRIPT s.charAt(int)方法:)
今天学习点什么呢?
。。。
今天我们来学习java中,String.charAt()方法。char charAt(int index):获取字符串中指定位置的字符。
●
●
获取方法名:
1. public void testStringCharAt() {
2. String str="I`m a freshman!";
3. System.out.println("charAt(2):-"+str.charAt(2));//提取索引为3的位置的字符
4. ...
5. ...
6. }
●
执行:
charAt(2):-m
…
●
●
1.描述
java.lang.String.charAt() 方法返回指定索引处的char值。索引范围是从0到length() - 1。对于数组索引,序列的第一个char值是在索引为0,索引1,依此类推
2.声明-以下是声明java.lang.String.charAt()方法
public char charAt(int index)
3.参数
index – 这是该指数的char值
4.返回值
此方法返回这个字符串的指定索引处的char值。第一个char值的索引为0.
5.异常
IndexOutOfBoundsException – 如果index参数为负或不小于该字符串的长度.
6.实例
public void Test {
String s =“I`m a freshman!”;
System.out.println(s.charAt(2));
}
运行结果是:
m
●
扩展:
在javascript中:
提取字符串字符
安全方法:
chartAt(position)
charCodeAt(position)
chartAt()
返回字符串中指定下标(位置)的字符串
1|var str = "I`m a freshman!";
2|str.charAt(2);
chartCodeAt()
返回字符串中指定索引的字符unicode编码
1|var str = "I`m a freshman!";
2|str.charCodeAt(2);
●
知识点随便,有点零碎,一点一滴记录自己的成长。。。。。。未完待续!敬请期待。。。