package edu.xalead;
public class Test {
static int aaa =20;
static void aab() {
}
public static void main(String[] args) {
/*
* 1、长度
* 2、字符串索引位置的字符
* 3、提取字串
* 4、拆分
* 5、合并
* 6、转换为字符数组
* 7、字符数组转换为字符串
* 8、把其他数据类转换为字符串
* 9、替换
* 10、正则表达式
* 11、根据字符返回索引位置
* 12.去除字符串前后的空格
* 13.把字符串改成大写
* 14.把字符串改成小写
* 15.把字符串改成字节数组表示
* 16.根据字节数组生成字符串
*/
int aaa =0;
String s = "qrdfa.efd, segr,gb1 25465";
//长度
System.out.println(s.length());
//根据字符串索引位置查找字符
System.out.println(s.charAt(4));
//提取字串
System.out.println(s.substring(4, 10));//左闭右开区间 包括第四个索引 不包括第十个索引
System.out.println("************************************");
//拆分
//String[] aa =s.split(" |,|\\.");
String[] aa =s.split(" ");
for(int i=0;i<aa.length;i++) {
System.out.println(aa[i]);
}
System.out.println("************************************");
//合并
System.out.println(s.concat("hello")); //产生垃圾 通常用StringBuffer或者StringBudder
//转换为字符数组
char[] tt =s.toCharArray();
for(int i=0;i<tt.length;i++) {
System.out.println(tt[i]);
}
//字符数组转换为字符串
String ss = new String(tt);
System.out.println(ss);
//String sss= new String("sfdrxhbfgjn");
//把其他数据类转换为字符串 //替换
String str = "we are happy";
System.out.println(str.replaceAll(" ", " "));
System.out.println(str.replace("we","you"));
// Test.aaa = 20;
// Test.aab();
System.out.println(String.valueOf(true));
//根据字符返回索引位置
System.out.println(s.indexOf('d',4));
//去除字符串前后的空格
String tttt = " zsdgbsdrt ";
System.out.println(tttt.trim());
//把字符串改成大写 把字符串改成小写
System.out.println(tttt.toUpperCase());
System.out.println(tttt.toLowerCase());
//把字符串改成字节数组表示
byte[] q = tttt.getBytes();
//根据字节数组生成字符串
System.out.println(new String(q));
}
}