Método Java String replace()
Exemplo
Retorna uma nova string onde todos os caracteres "l" são substituídos por caracteres "p":
String myStr = "Hello";
System.out.println(myStr.replace('l', 'p'));
Definição e uso
O replace()
método procura uma string por um caractere especificado e retorna uma nova string onde os caracteres especificados são substituídos.
Sintaxe
public String replace(char searchChar, char newChar)
Valores de parâmetro
Parameter | Description |
---|---|
searchChar | A char , representing the character that
will be replaced by the new character |
newChar | A char , representing the character to
replace the searchChar with |
Detalhes técnicos
Devoluções: | Um new String , onde o caractere especificado foi substituído pelo(s) novo(s) caractere(s) |
---|
❮ Métodos de String