1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.admin.servlet;
17
18 class StringUtils {
19
20
21
22
23
24
25
26
27
28
29
30
31 public static final String replace(final String text,
32 final String fromText, final String toText) {
33
34 if (text == null || fromText == null || toText == null) {
35 return null;
36 }
37 final StringBuilder builder = new StringBuilder(100);
38 int pos = 0;
39 int pos2 = 0;
40 while (true) {
41 pos = text.indexOf(fromText, pos2);
42 if (pos == 0) {
43 builder.append(toText);
44 pos2 = fromText.length();
45 } else if (pos > 0) {
46 builder.append(text.substring(pos2, pos));
47 builder.append(toText);
48 pos2 = pos + fromText.length();
49 } else {
50 builder.append(text.substring(pos2));
51 break;
52 }
53 }
54 return builder.toString();
55 }
56
57 }