Returns a string copy of the input character sequence, with each character that matches this matcher replaced by a given replacement character. For example: CharMatcher.is('a').replaceFrom("radar", 'o') ... returns "rodor". The default implementation uses {@link
(CharSequence sequence, char replacement)
| 751 | * @return the new string |
| 752 | */ |
| 753 | public String replaceFrom(CharSequence sequence, char replacement) { |
| 754 | String string = sequence.toString(); |
| 755 | int pos = indexIn(string); |
| 756 | if (pos == -1) { |
| 757 | return string; |
| 758 | } |
| 759 | char[] chars = string.toCharArray(); |
| 760 | chars[pos] = replacement; |
| 761 | for (int i = pos + 1; i < chars.length; i++) { |
| 762 | if (matches(chars[i])) { |
| 763 | chars[i] = replacement; |
| 764 | } |
| 765 | } |
| 766 | return new String(chars); |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Returns a string copy of the input character sequence, with each character that matches this |
no test coverage detected