标签:indexof 拼接 ace java abc sub nbsp bst 取字符串
String 字符串的声明:String string = “12345”;
1、字符串的拼接:
String str1 = "123";
String str2 = "456";
方法一:
System.out.println( str1 + sr2 );
方法二:
System.out..println( str1.concat( str2 ) );
2、字符串的删除与截取:
String str = "123ASDZXVCAAAA"
方法一:删除字符串中的所有数字
System.out.println( str.replaceAll ("\\d" , " ") );
方法二:截取字符串、删除
1、System.out.println( str.substring ( int i )); // 将字符串从下标为 i 开始截取,舍去下标为 i 之前的元素;
2、System.out.println( str.substring (int i , int j)); //将字符串由下标为 i 开始截取到 下标为 j;
3、System.out.println( str.replaceAll( "A", "" )); //将 str 字符串中的所有 A 替换为 “ ”;
3、ASCII 码转换:
String str = “123ASDasd”;
System.out.println ( str.charAt( int i) ); //获得下标为 i 的字符 的 ASCII 码,
4、获得指定下标元素
String str = "1234ABCD";
System. out .println(" str.indexOf (int i)"); //获得下标为 i 的元素;
5、检查字符串中是否含有某个元素
String str = “123qwer”;
if ( str.contanins("123")){
System.out.println("含有123")
}
标签:indexof 拼接 ace java abc sub nbsp bst 取字符串
原文地址:https://www.cnblogs.com/LuoYangAI01/p/9380624.html