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.
NULLoremptyreturns the same string.
what- The substring to replace. To leave the
sourcestring unaltered, setwhattonull.
with- The replacement text. To erase the substring identified by
what, setwithtonull.
Description
The
replaceAllmethod 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
redwithgreen:
clearResult(); String str = "This red looks really red."; String repStr = Utilities.replaceAll(str, "red", "green");The resulting value of
repStrwill be:
This green looks really green.
Home > Contents > Index > ![]()
Oracle JAVA Reference
Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.