[JAVA]String | java replace
[JAVA]String-字串處理的方法:concat、replace、replaceAll、replaceFirst、split、substringStringconcat(Stringstr)將指定字元串連接到此字元串的結尾。使用方式: Stringstring1="a"; Stringstring2="A"; System.out.println(string1.concat(string2));//aAStringreplace(charoldChar,charnewChar)返回一個新的字元串,它是通過用 newChar 替換此字元串中出現的所有 oldChar 得到的。Stringreplace(CharSequencetarget,CharSequencereplacement)使用指定的文字值替換序列替換此字元串所有比對文字值目標序...
[JAVA]String-字串處理的方法:concat、replace、replaceAll、replaceFirst、split、substringStringconcat(String str)將指定字元串連接到此字元串的結尾。使用方式:String string1 = "a"; String string2 = "A";
System.out.println(string1.concat(string2));//aA
Stringreplace(char oldChar, char newChar)返回一個新的字元串,它是通過用 newChar 替換此字元串中出現的所有 oldChar 得到的。Stringreplace(CharSequence target, CharSequence replacement)使用指定的文字值替換序列替換此字元串所有比對文字值目標序列的子字元串。StringreplaceAll(String regex, String replacement)使用給定的 replacement 替換此字元串所有比對給定的正則表達式[1]的子字元串。StringreplaceFirst(String regex, String replacement)使用給定的 replacement 替換此字元串比對給定的正則表達式[2]的第一個子字元串。使用方式:String string13 = "java"; System.out.println(string13.replace(a,1));//j1v1 System.out.println( string13.replace(string13.subSequence(2, 3), string13.subSequence(0, 1)));//jaja System.out.println(string13.replac...