zoukankan      html  css  js  c++  java
  • StringUtils

    package com.zxwa.ntmss.Excel;
    
    import org.apache.commons.lang3.ObjectUtils;
    import org.apache.poi.ss.formula.functions.T;
    import org.junit.Test;
    
    import java.math.BigDecimal;
    import java.text.DecimalFormat;
    import java.util.*;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.regex.PatternSyntaxException;
    
    /**
     * 字符串判断
     * 
     * @author 
     *
     */
    public class StringUtils {
    
    
        public static final String EMPTY = "";
    
        public static String formatNum(Double value) {
            BigDecimal b = new BigDecimal(value);
            String f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
            return f1;
        }
        /**
         * 判断字符串是否为空
         * 
         * @param str
         * @return
         */
        public static boolean isEmpty(String str) {
            if (null == str || "".equals(parseNull(str.trim())) || str.equals("undefined") || str.equals("null")) {
                return true;
            }
            return false;
        }
        
        
        /**
         * 判断字符串是否为空
         * 
         * @return
         */
        public static boolean isEquals(String str1,String str2) {
            if(isEmpty(str1)){
                if(isEmpty(str2)){
                    return true;
                }else {
                    return false;    
                }
            }else {
                if(isEmpty(str2)){
                    return false;
                }else if(str1.equals(str2)){
                    return true;    
                }else {
                    return false;
                }
            }
        }
          
          /**
         * 判断字符串是否为空
         * 
         * @param str
         * @return
         */
        public static boolean isEmptyObject(Object str) {
            if (null == str) {
                return true;
            }
            return false;
        }
    
        /**
         * 判断字符串是否为空
         * 
         * @param str
         * @return
         */
        public static boolean isNotEmpty(String str) {
            if (null == str || "".equals(str.trim()) || "null".equals(str.trim())) {
                return false;
            }
            return true;
        }
    
            
        /**
         * 
         * @Title: parseNull @Description: 爬虫的数据错误 当某个数据样式为 " "
         *         ,但又不是空时、调用该方法处理 @param: @param str @param: @return @return:
         *         String @throws
         */
        public static String parseNull(String str) {
            if (str == null || str.equals(" ") || str.equals("")) {
                str = "";
            }
            return str;
        }
    
        public static String null2Blank(Object obj) {
            if (obj == null || obj.toString().equals(" ") || obj.toString().equals("")) {
                return "";
            }
            return obj.toString();
        }
    
        public static String null2Zero(Object obj) {
            if (obj == null || obj.toString().equals(" ") || obj.toString().equals("")) {
                return "0";
            }
            return obj.toString();
        }
          
           /**
         * 
         * @Title: parseNull @Description: 对url后面的参数进行截取的 @param: @param
         *         str @param: @return @return: String @throws
         */
        public static String cleanUrl(String url) {
            if (StringUtils.isEmpty(url)) {
                return "";
            }
            if (url.contains("?")) {
                url = url.substring(0, url.indexOf("?"));
            }
            if (url.endsWith("/")) {
                url = url.substring(0, url.length() - 1);
            }
            return url;
        }
    
        /**
         * 获取32位ID
         * 
         * @return
         */
        public static String get32Uuid() {
            return UUID.randomUUID().toString().replaceAll("-", "");
        }
        
           /**
         * 判断多参是否都是空*/
        public static boolean isEmpty(String... fileNames) {
            for (String str : fileNames) {
                if (str != null && !"".equals(str.trim())) {
                    return false;
                }
    
            }
            return true;
        }
    
    
        public static boolean isNotEmpty(String... fileNames) {
            for (String str : fileNames) {
                if (str == null || "".equals(str.trim())) {
                    return false;
                }
    
            }
            return true;
        }
    
           public static String obj2String(Object obj) {
            return obj == null || "null".equals(obj) ? "" : obj.toString();
        }
    
        public static Integer string2Integer(String val) {
            if(StringUtils.isEmpty(val)){
                return 0;
            }
            return Integer.parseInt(val);
        }
    
        
    
        public static String replaceBlank(String str) {
            String dest = "";
            if (str != null) {
                Pattern p = Pattern.compile("\s*|	|
    |
    ");
                Matcher m = p.matcher(str);
                dest = m.replaceAll("");
            }
            return dest;
        }
    
        /**
         * 方法名:stringFilter 描述: 过滤特殊字符 参数:<br>
         * */
        public static String stringFilter(String str) throws PatternSyntaxException {
            String regEx = "[`~!$%^&*()+=|{}':;',\[\]<>/?~!##¥%……&*()——+|{}【】‘;:”“’。,、?\\]";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(str);
            return m.replaceAll("").trim();
        }
    
            /**
         * 
         * 方法名:toUpperCaseFirstOne<br>
         * 描述:首字母转大写<br>*/
        public static String toUpperCaseFirstOne(String s) {
            if (isEmpty(s)) {
                return s;
            }
            if (Character.isUpperCase(s.charAt(0))) {
                return s;
            } else {
                return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.subSequence(1, s.length()))
                        .toString();
            }
        }
    }
    
    故乡明
  • 相关阅读:
    Nagios HTTP WARNING: HTTP/1.1 403 Forbidden
    nagios监控的安装
    Linux里使用rz和sz命令
    Mariadb安装
    ubuntu16.04下载地址
    安装.msi格式安装包
    英文语法检测工具
    正确引用R及R包
    West world 西部世界
    Altered Carbon 碳变/副本
  • 原文地址:https://www.cnblogs.com/luweiweicode/p/14768897.html
Copyright © 2011-2022 走看看