
Android中的公共方法 - 字符串
dong_android
这个作者很懒,什么都没留下…
展开
-
格式化价格
/** 格式化价格**/public static String formatPrice(Double price){ String result = ""; try { DecimalFormat decimalFormat = new DecimalFormat("0.00"); result = decimalFormat.format(price); } c...原创 2015-05-04 13:56:27 · 229 阅读 · 0 评论 -
生成随机串(包含 字母+数字)
/** * 生成随机串(包含 字母+数字) * @param pwd_len // 随机数的长度 * @return 字符串 */public static String genRandomNum(int pwd_len) { final int maxNum = 50; int i; int count = 0; char[] str = { 'a', '...原创 2015-05-05 14:20:12 · 1149 阅读 · 0 评论 -
生成随机数纯数字
/** * 生成随机数纯数字 * @param length // 随机数的长度 * @return */public static String getRandom(int length) { Random random = new Random(); String rr = ""; Set set = new HashSet(); while (set.s...原创 2015-05-05 14:20:03 · 545 阅读 · 0 评论 -
字符串去回车去空格
/** * 字符串去回车去空格 * @param str * @return */public static String replaceBlank(String str) { String dest = ""; if (str != null) { Pattern p = Pattern.compile("\\s*|\t|\r|\n"); Matcher...原创 2015-05-05 14:19:55 · 457 阅读 · 0 评论 -
检测是否是手机号
/** * 检测是否是手机号 * @param mobileNum * @return */public static boolean isMobileNum(String mobileNum) { Pattern pattern = Pattern.compile("^(0|86|17951)?((13[0-9])|(145)|(147)|(170)|(17[6-8])|...原创 2015-05-05 14:19:46 · 312 阅读 · 0 评论 -
检测是否是Email
/** 检测是否是Email **/public static boolean isEmail(String email) { Pattern pattern = Pattern.compile("^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w{2,3}){1,3})$"); Matcher matcher = pattern.matcher(email); re...原创 2015-05-05 14:18:14 · 328 阅读 · 0 评论 -
检查是否固话
/** * 检查是否固话 * @param phoneNum * @return */public static boolean isPhoneNum(String phoneNum) { Pattern pattern = Pattern.compile("0\\d{2,3}-\\d{7,8}"); Matcher matcher = pattern.matcher(...原创 2015-05-04 13:57:37 · 146 阅读 · 0 评论 -
判断字符串中是否包含数字
/** 判断字符串中是否包含数字 **/public static boolean isContainsNum(String input) { int len = input.length(); for (int i = 0; i < len; i++) { if (Character.isDigit(input.charAt(i))) { return true; ...原创 2015-05-04 13:57:19 · 2116 阅读 · 0 评论 -
判断字符串中是否包含字母
/** 判断字符串中是否包含字母 **/public static boolean isContainsLetter(String input){ if(!StringUtil.isNull(input)){ Matcher matcher = Pattern.compile(".*[a-zA-Z]+.*").matcher(input); return matcher.ma...原创 2015-05-04 13:57:00 · 4778 阅读 · 0 评论 -
MD5 加密字符串
/*** MD5 加密* @param tastr* @return 字符串*/public static String getMD5(String tastr) { byte[] source = tastr.getBytes(); String s = null; char hexDigits[] = { // 用来将字节转换成 16 进制...2015-05-20 14:37:50 · 174 阅读 · 0 评论