tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > Basic > Char Matcher Replace From

Char Matcher Replace From 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using CharMatcher.replaceFrom() API. It returns a string where each matching character in the given char sequence is replaced with replacement char sequence.

File Name  :  
com/bethecoder/tutorials/guava/base_tests/CharMatcherReplaceTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.guava.base_tests;

import com.google.common.base.CharMatcher;

public class CharMatcherReplaceTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    String bigNumStr = "426,236,358";
    long myNum = Long.parseLong(CharMatcher.is(',').replaceFrom(bigNumStr, ""));
    
    System.out.println(myNum);
    System.out.println(CharMatcher.is(',').replaceFrom("123,456,789"""));
  }

}
   

It gives the following output,
426236358
123456789



 
  


  
bl  br