Home > Contents > Index >
Expanded TOC | Accordion TOC | Annotated TOC | Index
Utilities.replaceAll
Replaces all occurrences in a string of a specified substring with a new string.
Syntax
public static final String replaceAll(String source, String what, String with)Parameters
source
- The source string to be modified.
NULL
orempty
returns the same string.
what
- The substring to replace. To leave the
source
string unaltered, setwhat
tonull
.
with
- The replacement text. To erase the substring identified by
what
, setwith
tonull
.
Description
The
replaceAll
method replaces all occurrences in a string of a specified substring with a new string.Returns
Returns the new string.
Example
The following code fragment replaces both occurrences of
red
withgreen
:
clearResult(); String str = "This red looks really red."; String repStr = Utilities.replaceAll(str, "red", "green");The resulting value of
repStr
will be:
This green looks really green.
Home > Contents > Index > Oracle JAVA Reference
Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.