get Only Digits From String - Android java.lang

Android examples for java.lang:String Convert

Description

get Only Digits From String

Demo Code


public class Main{

    public static String getOnlyDigitsFromString(String textWithDigits) {
        if (isNullOrEmpty(textWithDigits)) {
            return "";
        }//from w w  w .  ja v a 2  s.c om
        return textWithDigits.replaceAll("\\D", "");
    }

}

Related Tutorials