1. 程式人生 > >字符串工具類

字符串工具類

temp () logs compile 判斷字符串 matcher public span pack

package com.cmos.ngoc.util;

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

/**
 * 字符串工具類
 * 
 */
public final class StringUtil {
    /** Private Constructor **/
    private StringUtil() {
    }
    
    /**
     * 判斷字符串是否非null && 非空字符 
     * 
     * @param param
     * @return
*/ public static boolean isNotEmpty(String param) { return param != null && !"".equals(param.trim()); } /** * 判斷字符串是否為null || 空字符串 * * @param param * @return */ public static boolean isEmpty(String param) { return param == null || "".equals(param.trim()); }
/** * 判斷是否為數?? * @param str * @return True為數?? */ public static boolean isNum(String str) { String regex = "^(-?\\d+)(\\.\\d+)?$"; return matchRegex(str, regex); } private static boolean matchRegex(String value, String regex) { Pattern pattern
= Pattern.compile(regex); Matcher matcher = pattern.matcher(value); return matcher.matches(); } }

字符串工具類