package cn.ctcare.android.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

    public static List<Long> getDigit(String text) {
        List<Long> digitList = new ArrayList<Long>();
        Pattern p = Pattern.compile("(\\d+)");
        Matcher m = p.matcher(text);
        while (m.find()) {
            String find = m.group(1).toString();
            digitList.add(Long.valueOf(find));
        }
        return digitList;
    }

    public static String getDigitFromString(String text) {
        List<Long> digitList = new ArrayList<Long>();

        StringBuffer sb = new StringBuffer();
        Pattern p = Pattern.compile("(\\d+)");
        Matcher m = p.matcher(text);
        while (m.find()) {
            String find = m.group(1).toString();
            sb.append(find);
            // digitList.add(Long.valueOf(find));
        }
        return sb.toString();
    }

    public static boolean isMobileNO(String mobiles) {
        Pattern p = Pattern
                .compile("^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static boolean isDouble(String value) {
        try {
            Double.parseDouble(value);
            if (value.contains("."))
                return true;
            return false;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public static int Double2Int(String s1) {
        // /double d = 1.233;
        // String s1 = String.valueOf(value);
        String s2 = s1.substring(0, s1.indexOf("."));
                //+ s1.substring(s1.indexOf(". ") + 1);
        int i = Integer.parseInt(s2);
        return i;
    }

}