Replaces all occurrences of a String within another String. The String to be replaced will be replaced ignoring cases, all other cases are preserved in the returned string
- 引数:
-
| sourceString | source String |
| replace | text to replace, case insensitive |
| with | replacement text |
- 戻り値:
- the text with any replacements processed,
null if null String input
Strings.java の 75 行で定義されています。00077 {
00078 if (sourceString == null || replace == null || with == null)
00079 {
00080 return sourceString;
00081 }
00082 String lower = sourceString.toLowerCase();
00083 int shift = 0;
00084 int idx = lower.indexOf(replace);
00085 int length = replace.length();
00086 StringBuffer resultString = new StringBuffer(sourceString);
00087 do
00088 {
00089 resultString = resultString.replace(idx + shift, idx + shift + length,
00090 with);
00091 shift += with.length() - length;
00092 idx = lower.indexOf(with, idx + length);
00093 }
00094 while (idx > 0);
00095
00096 return resultString.toString();
00097 }
|