标签:方法 [] 定位 tchar net 范围 子串 others begin
String.equals()方法源代码:
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = value.length;
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
while (n-- != 0) {
if (v1[i] != v2[i])
return false;
i++;
}
return true;
}
}
return false;
}
String类方法的使用说明:
1.int Length():
返回字符串长度。
2.char charAt(int n):
返回指定索引处的char值,索引范围为从0到length() - 1. 3.getChars(int srcBegin,int srcEnd, char[] dst,int dstBegin)
获取从指定位置起的子串复制到字符数组中.要复制的第一个字符位于索引srcBegin处;要复制的最后一个字符位于索引srcEnd-1处(因此要复制的字符总数是srcEnd-srcBegin)。要复制到dst子数组的字符从索引dstBegin处开始,并结束于索引.
4.String replace(char oldChar,char newChar)子串替换:
返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有oldChar得到的。如果oldChar在此String对象表示的字符序列中没有出现,则返回对此String对象的引用。否则,创建一个新的String对象,它所表示的字符序列除了所有的oldChar都被替换为newChar之外,与此String对象表示的字符序列相同。
5.String toLowerCase():
将此String中的所有字符都转换为小写
6.String toUpperCase():
将此String中的所有字符都转换为大写
7.String trim():
去除头尾空格:
8.char[] toCharArray():
将字符串对象转换为字符数组
标签:方法 [] 定位 tchar net 范围 子串 others begin
原文地址:http://www.cnblogs.com/ssyh/p/7729929.html