字符串的操作

时间:2021-11-20 14:42:23

字符串的操作

  String string = new String("zxcvbnm");
System.out.println("字符串长度:"+string.length());
System.out.println("字符串全变成大写:"+string.toUpperCase());
System.out.println("大写的与小写比较返回TRUE:"+string.equalsIgnoreCase("ZXCVBNM"));
System.out.println("某一字符在字符串的位置:"+string.indexOf("c")+1);
System.out.println("截取字符串:"+string.substring(3, string.length()));
String string1 = new String(" zxcvbnm ");
System.out.println("去除前导和后导空格:"+string1.trim());
for (int i = 0; i < string.length(); i++) {
System.out.println("第"+(i+1)+"个字符:"+string.charAt(i));

  字符串的操作

字符串的操作字符串的操作字符串的操作