您当前的位置: 首页 > 

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

字符串工具类

梁云亮 发布时间:2021-07-16 20:20:11 ,浏览量:2

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class StringUtil {
/**
     * 查找字符串str中包含的字符串s的个数
     * 通过indexOf()寻找指定字符串,截取指定字符串后面的部分,再次寻找,直到找完所有
     * @param str
     * @param s
     * @return
     */
    public static int countString(String str, String s) {
        int count = 0;
        while (str.indexOf(s) != -1) {
            str = str.substring(str.indexOf(s) + 1);
            count++;
        }
        return count;
    }

    /**
     * 判断参数是否是JSON字符串
     * @param str
     * @return
     */
    public static boolean isJSONType(String str) {
        boolean result = false;
        if (str != null && str.length() > 0) {
            str = str.trim();
            if (str.startsWith("{") && str.endsWith("}")) {
                result = true;
            } else if (str.startsWith("[") && str.endsWith("]")) {
                result = true;
            }
        }
        return result;
    }
    /**
     * null、“”都返回true
     * 只要有任意一个字符(包括空白字符)就不为空
     *
     * @param cs
     * @return
     */
    public static boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    /**
     * null、“”、空格都返回true
     * 判断字符串是否为空字符串,全部空白字符也为空。
     *
     * @param cs
     * @return
     */
    public static boolean isBlank(CharSequence cs) {
        int strLen;
        if (cs != null && (strLen = cs.length()) != 0) {
            for (int i = 0; i             
关注
打赏
1665409997
查看更多评论
0.0435s