Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement character. For example: {@snippet : CharMatcher.is('a').replaceFrom("radar", 'o') } ... returns {@code "rodor"}. <p>The default implementation uses {@link #indexIn(CharSequence)
(CharSequence sequence, char replacement)
| 678 | * @return the new string |
| 679 | */ |
| 680 | public String replaceFrom(CharSequence sequence, char replacement) { |
| 681 | String string = sequence.toString(); |
| 682 | int pos = indexIn(string); |
| 683 | if (pos == -1) { |
| 684 | return string; |
| 685 | } |
| 686 | char[] chars = string.toCharArray(); |
| 687 | chars[pos] = replacement; |
| 688 | for (int i = pos + 1; i < chars.length; i++) { |
| 689 | if (matches(chars[i])) { |
| 690 | chars[i] = replacement; |
| 691 | } |
| 692 | } |
| 693 | return new String(chars); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Returns a string copy of the input character sequence, with each matching BMP character |