Java Metoda replace ()
Metoda replace () zastępuje cały ciąg znaków staryznak z nowyznak charakter i zwraca nowy ciąg zastępczy.
gramatyka
public String replace(char oldChar, char newChar)
parametry
staryznak - oryginalne znaków.
nowyznak - nowa postać.
Wartość zwracana
Zastąpiony nowym ciągiem po pokoleniu.
Przykłady
public class Test { public static void main(String args[]) { String Str = new String("hello"); System.out.print("返回值 :" ); System.out.println(Str.replace('o', 'T')); System.out.print("返回值 :" ); System.out.println(Str.replace('l', 'D')); } }
Powyższe wyniki wykonania programu:
返回值 :hellT 返回值 :heDDo