DOCX

string

By Holly Carroll,2014-11-06 22:53
23 views 0
package com.koubei.util; import java.beans.XMLDecoder; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.L..

package com.koubei.util;

import java.beans.XMLDecoder;

    import java.io.BufferedInputStream;

    import java.io.ByteArrayInputStream;

    import java.io.UnsupportedEncodingException; import java.net.URLEncoder;

    import java.text.DecimalFormat;

    import java.util.ArrayList;

    import java.util.HashMap;

    import java.util.HashSet;

    import java.util.Iterator;

    import java.util.LinkedHashMap;

    import java.util.List;

    import java.util.Map;

    import java.util.Set;

    import java.util.regex.Matcher;

    import java.util.regex.Pattern;

    import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.logging.Log;

    import org.apache.commons.logging.LogFactory;

import com.opensymphony.util.TextUtils;

/**

     * @author chen

     *

     */

    public class StringUtil {

     private static Pattern numericPattern = Pattern.compile("^[0-9\\-]+$");

     private static Pattern numericStringPattern = Pattern

     .compile("^[0-9\\-\\-]+$");

     private static Pattern floatNumericPattern = Pattern

     .compile("^[0-9\\-\\.]+$");

     private static Pattern abcPattern = Pattern.compile("^[a-z|A-Z]+$");

     public static final String splitStrPattern = ",||;|||\\.||-|_|\\(|\\)|\\[|\\]|\\{|\\}|\\\\|/|

    | |\"";

     private static Log logger = LogFactory.getLog(StringUtil.class);

     /**

     * 判断是否数字表示

     *

     * @param src

     * 源字符串

     * @return 是否数字的标志

     */

     public static boolean isNumeric(String src) {

     boolean return_value = false;

     if (src != null && src.length() > 0) {

     Matcher m = numericPattern.matcher(src);

     if (m.find()) {

     return_value = true;

     }

     }

     return return_value;

     }

     /**

     * 判断是否数字表示

     *

     * @param src

     * 源字符串

     * @return 是否数字的标志

     */

     public static boolean isNumericString(String src) {

     boolean return_value = false;

     if (src != null && src.length() > 0) {

     Matcher m = numericStringPattern.matcher(src);

     if (m.find()) {

     return_value = true;

     }

     }

     return return_value;

     }

     /**

     * 判断是否纯字母组合

     *

     * @param src

     * 源字符串

     * @return 是否纯字母组合的标志

     */

     public static boolean isABC(String src) {

     boolean return_value = false;

     if (src != null && src.length() > 0) {

     Matcher m = abcPattern.matcher(src);

     if (m.find()) {

     return_value = true;

     }

     }

     return return_value;

     }

     /**

     * 判断是否浮点数字表示

     *

     * @param src

     * 源字符串

     * @return 是否数字的标志

     */

     public static boolean isFloatNumeric(String src) {

     boolean return_value = false;

     if (src != null && src.length() > 0) {

     Matcher m = floatNumericPattern.matcher(src);

     if (m.find()) {

     return_value = true;

     }

     }

     return return_value;

     }

     /**

     * string array or list用给定的符号symbol连接成一个字符串

     *

     * @param array

     * @param symbol

     * @return

     */

     public static String joinString(List array, String symbol) {

     String result = "";

     if (array != null) {

     for (int i = 0; i < array.size(); i++) {

     String temp = array.get(i).toString();

     if (temp != null && temp.trim().length() > 0)

     result += (temp + symbol);

     }

     if (result.length() > 1)

     result = result.substring(0, result.length() - 1);

     }

     return result;

     }

     public static String subStringNotEncode(String subject, int size) {

     if (subject != null && subject.length() > size) {

     subject = subject.substring(0, size) + "...";

     }

     return subject;

     }

     public static String subString(String subject, int size) {

     subject = TextUtils.htmlEncode(subject);

     if (subject.length() > size) {

     subject = subject.substring(0, size) + "...";

     }

     return subject;

     }

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com