get Numbers from a string - Android java.lang

Android examples for java.lang:Integer

Description

get Numbers from a string

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String getNumbers(String content) {
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            return matcher.group(0);
        }/*from w  w w . j  a va 2 s.  co  m*/
        return "";
    }

}

Related Tutorials