作者在 2017-05-28 12:21:43 发布以下内容
public static void main(String[] args) {
// TODO Auto-generated method stub
String aString = "hellocensi @gmail.com " ;
System.out.println(aString);
int lenthString=aString.length();
System.out.println("way1:"+lenthString);//常用方法1:获取字符串长度
char str[]=aString.toCharArray(); //常用方法2 :转换为字符数组
System.out.print("way2:");
System.out.println(str);
for(int i=0;i<aString.length();i++)
System.out.print(str[i]+" ");
System.out.println("\nway3:"+aString.charAt(8));//常用方法3:根据下标获取单个字符
System.out.print("way4:"+"\n"); //常用方法4:编程byte数组
byte mybytes[]=aString.getBytes();
for(int i=0;i<mybytes.length;i++)
System.out.print(mybytes[i]+" ");
System.out.print("\n");
for(int i=0;i<mybytes.length;i++)
System.out.print((char)mybytes[i]); //byte转换成char
System.out.println("\nway5:"); //常用方法5:查找单个字符
System.out.println(aString.indexOf('@'));
System.out.println(aString.indexOf('#')); //找不到返回-1
String aString1 = " hello jack";
System.out.println("way6:"); //常用方法6:去掉字符串前面的空格
System.out.println(aString1);
System.out.println(aString1.trim());
/*还有的常用方法有:7.从字符串中截取子字符串 :subString()
8.大小写转换:toLowerCase()、toUpperCase()
9.判断字符串的开头结尾字符:endsWith()、startWith()
10.替换字符串中的一个字符:replace()
...
*/
}
// TODO Auto-generated method stub
String aString = "hellocensi @gmail.com " ;
System.out.println(aString);
int lenthString=aString.length();
System.out.println("way1:"+lenthString);//常用方法1:获取字符串长度
char str[]=aString.toCharArray(); //常用方法2 :转换为字符数组
System.out.print("way2:");
System.out.println(str);
for(int i=0;i<aString.length();i++)
System.out.print(str[i]+" ");
System.out.println("\nway3:"+aString.charAt(8));//常用方法3:根据下标获取单个字符
System.out.print("way4:"+"\n"); //常用方法4:编程byte数组
byte mybytes[]=aString.getBytes();
for(int i=0;i<mybytes.length;i++)
System.out.print(mybytes[i]+" ");
System.out.print("\n");
for(int i=0;i<mybytes.length;i++)
System.out.print((char)mybytes[i]); //byte转换成char
System.out.println("\nway5:"); //常用方法5:查找单个字符
System.out.println(aString.indexOf('@'));
System.out.println(aString.indexOf('#')); //找不到返回-1
String aString1 = " hello jack";
System.out.println("way6:"); //常用方法6:去掉字符串前面的空格
System.out.println(aString1);
System.out.println(aString1.trim());
/*还有的常用方法有:7.从字符串中截取子字符串 :subString()
8.大小写转换:toLowerCase()、toUpperCase()
9.判断字符串的开头结尾字符:endsWith()、startWith()
10.替换字符串中的一个字符:replace()
...
*/
}