(String s, String oldSub, String newSub)
| 145 | } |
| 146 | |
| 147 | public static String replace(String s, String oldSub, String newSub) { |
| 148 | if ((s == null) || (oldSub == null) || (newSub == null)) { |
| 149 | return null; |
| 150 | } |
| 151 | |
| 152 | int y = s.indexOf(oldSub); |
| 153 | |
| 154 | if (y >= 0) { |
| 155 | StringBuilder sb = new StringBuilder(); |
| 156 | int length = oldSub.length(); |
| 157 | int x = 0; |
| 158 | |
| 159 | while (x <= y) { |
| 160 | sb.append(s.substring(x, y)); |
| 161 | sb.append(newSub); |
| 162 | x = y + length; |
| 163 | y = s.indexOf(oldSub, x); |
| 164 | } |
| 165 | |
| 166 | sb.append(s.substring(x)); |
| 167 | |
| 168 | return sb.toString(); |
| 169 | } else { |
| 170 | return s; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | public static String replace(String s, String[] oldSubs, String[] newSubs) { |
| 175 | if ((s == null) || (oldSubs == null) || (newSubs == null)) { |
no test coverage detected