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
查看更多评论