public class LearnString {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1 = new String("hello");
String s2 = new String("李");
String s = s1+" "+s2;
System.out.println(s);
System.out.println(s.length()+""); //汉字占有两个长度。
System.out.println(s.indexOf("e")+""); //字符串下标从0开始。
System.out.println(s.charAt(2)); //查找某一位的字符。
//截取字符串
System.out.println(s.substring(1,7)); //汉字有两个长度,如果填6则“李”不打印出来,填7则打印出来
System.out.println(s.replace("l","r")); //替换所有的字符
String scf = "123,456,789,aaa,bbb,ccc";
String[] newsc = scf.split(",", 2);
for (int i = 0;i<newsc.length;i++){
System.out.println(newsc[i]);
}
/** 输出:123
* 456,789,aaa,bbb,ccc
*/
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1 = new String("hello");
String s2 = new String("李");
String s = s1+" "+s2;
System.out.println(s);
System.out.println(s.length()+""); //汉字占有两个长度。
System.out.println(s.indexOf("e")+""); //字符串下标从0开始。
System.out.println(s.charAt(2)); //查找某一位的字符。
//截取字符串
System.out.println(s.substring(1,7)); //汉字有两个长度,如果填6则“李”不打印出来,填7则打印出来
System.out.println(s.replace("l","r")); //替换所有的字符
String scf = "123,456,789,aaa,bbb,ccc";
String[] newsc = scf.split(",", 2);
for (int i = 0;i<newsc.length;i++){
System.out.println(newsc[i]);
}
/** 输出:123
* 456,789,aaa,bbb,ccc
*/
}
}
查找指定字符的位置:indexOf
获取指定索引位置的字符:charAt
截取指定位置字符串:substring
去空格:trim()
字符串替换:replace(“a”,“A”);
字符串是否相等;
大小写转换;
字符串分割:split
字符串格式化
正则表达式;
stringbuilder