Java Utililty Methods String Replace

List of utility methods to do String Replace

  1. HOME
  2. Java
  3. S
  4. String Replace

Description

The list of methods to do String Replace are organized into topic(s).

Method

List getLineBreakOffsets(String replacementString)
get Line Break Offsets
ArrayList<Integer> ret = new ArrayList<Integer>();
int lineBreaks = 0;
int ignoreNextNAt = -1;
for (int i = 0; i < replacementString.length(); i++) {
 char c = replacementString.charAt(i);
 if (c == '\r') {
 lineBreaks++;
 ret.add(i);
...
String replace(final String text, final String search, final String replace)
Replaces all occurrences of search in text by replace and returns the result.
if (text == null) {
 return "";
final int len = search != null ? search.length() : 0;
if (len == 0) {
 return text;
final StringBuffer result = new StringBuffer();
...
String replace(String origStr, char oldChar, String newStr)
Replaces a character of a String with characters in the specified new substring.
return replaceAll(origStr, oldChar, newStr);
String replace(String source, Properties properties)
replace
HashMap<String, String> map = new HashMap<String, String>(properties.size());
Iterator<Object> iter = properties.keySet().iterator();
while (iter.hasNext()) {
 String key = (String) iter.next();
 map.put(key, properties.getProperty(key));
return replace(source, map);
String replace(String source, String oldChars, String newChars)
Method replace.
if (source == null)
 return null;
if (oldChars == null || oldChars.length() == 0 || newChars == null || source.indexOf(oldChars) == -1)
 return source;
if (source.equals(oldChars))
 return newChars;
StringBuffer buffer = new StringBuffer(source.length());
List<String> tokens = split(source, oldChars);
...
String replace(String source, String stringToReplace, String replacementString, boolean matchCase)
Searches for a string within a specified string and replaces every match with another string.
if (null == source) {
 return null;
if (null == stringToReplace) {
 return source;
if (null == replacementString) {
 return source;
...
String replace(String str)
Replaces the /'s with this systems file separator
String sep = System.getProperty("file.separator");
if (sep.equals("/"))
 return str;
StringTokenizer tok = new StringTokenizer(str, "/");
String tmp = tok.nextToken();
while (tok.hasMoreTokens()) {
 tmp += sep + tok.nextToken();
if (str.endsWith("/"))
 tmp += sep;
return tmp;
String replace(String string, String pattern, String value)
Replaces all occurrences of "pattern" in "string" with "value"
if (pattern.length() == 0)
 return string;
StringBuilder returnValue = new StringBuilder();
int patternLength = pattern.length();
while (true) {
 int idx = string.indexOf(pattern);
 if (idx < 0) {
 break;
...
String replace(String string, String pattern, String value)
Replaces all occurrences of "pattern" in "string" with "value"
if (pattern.length() == 0) {
 return string;
StringBuffer returnValue = new StringBuffer();
int patternLength = pattern.length();
while (true) {
 int idx = string.indexOf(pattern);
 if (idx < 0) {
...
String[] replace(String target, String replacement, String... args)
replace
ArrayList<String> ret = new ArrayList<String>();
for (String s : args)
 ret.add(s.replace(target, replacement));
return ret.toArray(new String[] {});


AltStyle によって変換されたページ (->オリジナル) /