| 344 | } |
| 345 | |
| 346 | public String replace(char oldChar, char newChar) { |
| 347 | if (data instanceof char[]) { |
| 348 | char[] buf = new char[length]; |
| 349 | for (int i=0; i < length; i++) { |
| 350 | if (charAt(i) == oldChar) { |
| 351 | buf[i] = newChar; |
| 352 | } else { |
| 353 | buf[i] = charAt(i); |
| 354 | } |
| 355 | } |
| 356 | return new String(buf, 0, length, false); |
| 357 | } else { |
| 358 | byte[] buf = new byte[length]; |
| 359 | byte[] orig = (byte[])data; |
| 360 | byte oldByte = (byte)oldChar; |
| 361 | byte newByte = (byte)newChar; |
| 362 | for (int i=0; i < length; i++) { |
| 363 | if (orig[i+offset] == oldByte) { |
| 364 | buf[i] = newByte; |
| 365 | } else { |
| 366 | buf[i] = orig[i+offset]; |
| 367 | } |
| 368 | } |
| 369 | return new String(buf, 0, length, false); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | public String substring(int start) { |
| 374 | return substring(start, length); |