CharMatcher collapseFrom - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for CharMatcher collapseFrom method.

This code example shows how to use the following methods:collapseFrom
        assertThat(CharMatcher.DIGIT.or(CharMatcher.JAVA_LETTER).retainFrom("Hello 1234 567")).isEqualTo("Hello1234567");
    } 
 
    @Test
    public void shouldCollapseAllDigitsByX() throws Exception {
        assertThat(CharMatcher.DIGIT.collapseFrom("Hello 1234 567", 'x')).isEqualTo("Hello x x");
    } 
 
     @Test
    public void shouldReplaceAllDigitsByX() throws Exception {
        assertThat(CharMatcher.DIGIT.replaceFrom("Hello 1234 567", 'x')).isEqualTo("Hello xxxx xxx");
    } 
 
    @Test
    public void shouldCountDigits() throws Exception {
        assertThat(CharMatcher.DIGIT.countIn("Hello 1234 567")).isEqualTo(7);
    } 
 
    @Test
    public void shouldReturnFirstIndexOfFirstWhitespace() throws Exception {
3
CodeRank
This code example shows how to use the following methods:collapseFrom
     * @return Array of Characters after converting tab, newline, etc. to 
     *         single space. 
     */ 
    @Override 
    public char[] process(char[] procText) {
        return CharMatcher.WHITESPACE.collapseFrom(new String(procText), ' ').toCharArray();
    } 
} 
4
CodeRank
collapseFrom Method Overview
Returns a string copy of the input character sequence, with each group of consecutive characters that match this matcher replaced by a single replacement character.
See Code Examples for other Guava CharMatcher Methods: