码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA工具类-StrUtils

时间:2017-02-21 19:13:28      阅读:725      评论:0      收藏:0      [点我收藏+]

标签:support   ace   验证   nbsp   字符串   str   acea   utils   bsp   

public class StrUtils {
    public static final String UTF_8 = "UTF-8";
    
    /**
     * 去掉小数字符串后面无用的零
     */
    public static String replaceTheTailZero(String value){
        if(StringUtils.isEmpty(value)){
            return value;
        }        
        if(value.indexOf(".") > 0){
            value =value.replaceAll("0+?$", "");//去掉后面无用的零
            value =value.replaceAll("[.]$", "");//如小数点后面全是零则去掉小数点
        }
        return value;
    }
    
    /**
     * UTF-8字符长度换算
     */
    public static int getStrByteLen(String value) throws UnsupportedEncodingException{
        if(StringUtils.isEmpty(value)){
            return 0;
        }
        return value.getBytes(UTF_8).length;
    }

    /**
     * 验证是否为空
     */
    public static boolean validationIsNull(String value) {
        if (StringUtils.isEmpty(value)) {
            return true;
        }
        if (StringUtils.trim(value).length() == 0) {
            return true;
        }
        return false;
    }
}

 

JAVA工具类-StrUtils

标签:support   ace   验证   nbsp   字符串   str   acea   utils   bsp   

原文地址:http://www.cnblogs.com/moulton/p/6424558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!