/**
 *
 */
package com.sign.utils;
import java.util.regex.Pattern;

/**
 * @author Administrator
 * create on 2015年6月3日
 *
 */

public class StringUtil {

    private static Pattern regidPattern = Pattern.compile("[\\w-]*");

    public static boolean isDigital(String str){
        Pattern p = Pattern.compile("(0|([1-9][0-9]*))(\\.[0-9]+)?");
        return p.matcher(str).matches();
    }

    public static boolean isChinese(String scr) {
        return !regidPattern.matcher(scr).matches();
    }

    /**
     *
     * @param s
     * @return
     */
    public static boolean isAllChinese(String s) {
          if (null == s || "".equals(s.trim())) return false;
          for (int i = 0; i < s.length(); i++) {
            if (!isChinese(s.charAt(i)))    return false;
          }
          return true;
    }

    /**
     *
     * @param s
     * @return
     */
    public static boolean isContainsChinese(String s){
          if (null == s || "".equals(s.trim())) return false;
          for (int i = 0; i < s.length(); i++) {
            if (isChinese(s.charAt(i)))    return true;
          }
          return false;
    }

    /**
     *
     * @param a char
     * @return boolean
     */
    public static boolean isChinese(char a) {
         int v = (int)a;
         return (v >=19968 && v <= 171941)||v==183;
    }

    /**
     *
     * @param input
     * @return String
     */
    public static final String escapeHTMLTag(String input) {
        if (input == null) {
            return "";
        }
        input = input.trim().replaceAll("&", "&amp;");
        input = input.trim().replaceAll("<", "&lt;");
        input = input.trim().replaceAll(">", "&gt;");
        input = input.trim().replaceAll("\t", "    ");
        input = input.trim().replaceAll("\r\n", "\n");
        input = input.trim().replaceAll("\n", "<br>");
        input = input.trim().replaceAll("  ", " &nbsp;");
        input = input.trim().replaceAll("'", "'");
        input = input.trim().replaceAll("\\\\", "\");
        return input;
    }

    public static String cleanHtmlTag(String htmlText) {
        String reg = "</?[a-z][a-z0-9]*[^<>]*>?";
        return htmlText.replaceAll(reg, "");
    }

    /**
     *
     *
     *
     * @param str
     * @return
     */
    public static String null2Trim(String str) {
        return str == null ? "" : str.trim();
    }

    public static String replaceXmlEntity(String xml){
        xml = xml.replaceAll("&amp;", "&");
        xml = xml.replaceAll("&quot;", "\"");
        xml = xml.replaceAll("&gt;", ">");
        xml = xml.replaceAll("&nbsp;", " ");
        xml = xml.replaceAll("&apos;", "'");
        return xml;
    }

    /**
     *
     *
     * @param Str
     * @return
     */
    public static boolean isEmpty(String str) {
        return !notEmpty(str);
    }

    /**
     *
     *
     * @param Str
     * @return
     */
    public static boolean notEmpty(String str) {
        if (str != null && str.trim().length() > 0)
            return true;
        return false;
    }

    public static void main(String[] argv)
    {
        boolean result = StringUtil.isDigital("0.1");

//        int length = StringUtil.getStringLength("呵呵a");

        int length = "呵呵".length();

        System.out.println(result);

        System.out.println(length);
    }
}

java StringUtils的更多相关文章

  1. [JAVA][StringUtils]字符串工具类的常用方

    StringUtils 方法的操作对象是 java.lang.String 类型的对象,是 JDK 提供的 String 类型操作方法的补充,并且是 null 安全的(即如果输入参数 String 为 ...

  2. JAVA StringUtils方法全集

    StringUtils方法全集 org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供 的String类型操作 ...

  3. JAVA StringUtils工具类

    org.apache.commons.lang Class StringUtils java.lang.Object org.apache.commons.lang.StringUtils publi ...

  4. JAVA StringUtils需要导入的包

    <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang --> <dependency> <g ...

  5. JAVA StringUtils 坑汇总

    1 StringUtils.split() VS String.split(); public static void main(String args[]){            String r ...

  6. ElasticSearch5在Ubuntu系统下的安装和Java调用

    ElasticSearch是开源搜索平台的新成员,实时数据分析的神器.可以理解为作为搜索的数据库,可以提供搜索功能.对比关系型数据库,具有以下的相似关系: 关系型数据库 数据库 表 行 列 Elast ...

  7. java 数据脱敏

    所谓数据脱敏是指对某些敏感信息通过脱敏规则进行数据的变形,实现敏感隐私数据的可靠保护.在涉及客户安全数据或者一些商业性敏感数据的情况下,在不违反系统规则条件下,对真实数据进行改造并提供测试使用,如身份 ...

  8. Atitit.ati  str  字符串增强api

    Atitit.ati  str  字符串增强api 1. java StringUtils方法全览 分类: Java2011-11-30 17:22 8194人阅读 评论(2) 收藏 举报 javas ...

  9. Atitit.ati&#160;&#160;str&#160;&#160;字符串增强api

    Atitit.ati  str  字符串增强api 1. java StringUtils方法全览 分类: Java2011-11-30 17:22 8194人阅读 评论(2) 收藏 举报 javas ...

随机推荐

  1. Element 'dependencies' cannot have character[children],because the type's content type is elemen

    问题描述: Element 'xxxxxxx' cannot have character [children],because the type's content type is element- ...

  2. RDS MySQL 表上 Metadata lock 的产生和处理

    https://help.aliyun.com/knowledge_detail/41723.html?spm=5176.7841698.2.18.vNfPM3

  3. HDU 4525

    也是水题了,不过注意负负也可以为正就好了. 今天看见bestcoder上的人那么厉害,唉,我什么时候才能赶上啊.. #include <iostream> #include <cst ...

  4. [Vue] Lazy Load a Route by using the Dynamic Import in Vue.js

    By default, vue-router doesn’t lazy load the routes unless you tell it to do it. Lazy loading of the ...

  5. HDU 2563 统计问题(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=2563 将向上移的步数设为a[n],将向左右移的步数设为b[n],有a[n]=a[n-1]+b[n-1 ...

  6. NJUPT JAVA语言 流处理程序设计

    一. 实验目的和要求 实验目的和要求:要求学生能在学习和理解课堂学习内容中JAVA流编程理论的基础上,学习并逐步掌握JAVA流程序的编写和调试,学习依据处理需求对不同流的正确选择使用和组合用法. 实验 ...

  7. Spring源代码解析和配置文件载入

    Spring类的继承结构图: Spring运用了大量的模板方法模式和策略模式,所以各位看源代码的时候,务必留意,每个继承的层次都有不同的作用.然后将同样的地方抽取出来,依赖抽象将不同的处理依照不同的策 ...

  8. 托管在IIS上的wcf,在启动的时候,写log

    https://blogs.msdn.microsoft.com/wenlong/2006/01/11/how-to-initialize-hosted-wcf-services/ Using App ...

  9. Android 6.0 中TimePicker显示为滚动样式的方法

    在Android6.0中,TimePicker控件的默认样式为转盘的样式,就像这个样子: 如果想要显示为之前的滚动样式的话也很简单,只要在布局文件中设置TimePicker的timePickerMod ...

  10. [BZOJ 1735] Muddy Fields

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1735 [算法] 二分图最小覆盖 [代码] #include<bits/stdc ...