Learn Java Programming - String Class Tutorials replace(...)

Veröffentlicht am: 26 August 2015
auf dem Kanal: Daniel Ross
2,446
14

The replace() method is overloaded and has two different signatures. The replace(char oldChar, char newChar) simply returns a string with all characters that match the first parameter oldchar replaced with the character specified by the second parameter newChar. For example:
String s = "Don't bring these to the airport: pocket knife; liquid bleach; gasoline; guns; etc.";
String version1 = s.replace(';', ',');
System.out.println( version1); // Don't bring these to the airport: pocket knife, liquid bleach, gasoline, guns, etc.

The replace(CharSequence target, CharSequence replacement) simply returns a string with all substrings that match first parameter target replaced with the substring specified by the second parameter replacement. For example:
String u = "The quick brown fox jumps over the lazy dog.";
u = u.replace("the", "my");
System.out.println(u); // The quick brown fox jumps over my lazy dog.


Auf dieser Seite können Sie das Online-Video Learn Java Programming - String Class Tutorials replace(...) mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Daniel Ross 26 August 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,446 Mal angesehen und es wurde von 14 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!