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)
| 838 | |
| 839 | |
| 840 | public String replaceFrom(CharSequence sequence, char replacement) { |
| 841 | String string = sequence.toString(); |
| 842 | int pos = indexIn(string); |
| 843 | if (pos == -1) { |
| 844 | return string; |
| 845 | } |
| 846 | char[] chars = string.toCharArray(); |
| 847 | chars[pos] = replacement; |
| 848 | for (int i = pos + 1; i < chars.length; i++) { |
| 849 | if (matches(chars[i])) { |
| 850 | chars[i] = replacement; |
| 851 | } |
| 852 | } |
| 853 | return new String(chars); |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * Returns a string copy of the input character sequence, with each character that matches this |
no test coverage detected