Java中StringHelp
2024-10-06 09:08:24
import java.util.Collection;
import java.util.Map;
import java.util.UUID; public class StringHelper { public static final String EMPTY=""; public StringHelper(){} /**
* 判断字符串是否为NULL或空值
* @param str
* @return
*/
@SuppressWarnings("rawtypes")
public static Boolean IsEmptyOrNull(Object obj)
{
if (obj == null)
return true;
if ("".equals(obj))
return true;
if (obj instanceof String) {
if (((String) obj).length() == 0) {
return true;
}
} else if (obj instanceof Collection) {
if (((Collection) obj).size() == 0) {
return true;
}
} else if (obj instanceof Map) {
if (((Map) obj).size() == 0) {
return true;
}
}
return false;
} /**
* NULL转String
* @param obj
* @return
*/
public static String TranString(Object obj)
{
if (obj == null)
return ""; return obj.toString();
} /**
* NULL转String
* @param obj
* @param defaultval 默认值
* @return
*/
public static String TranString(Object obj, String defaultval)
{
if (obj == null)
return defaultval; return obj.toString();
} /**
* 模糊查询%_通配符转换
* @param str
* @return
*/
public static String TranSeachString(Object obj)
{
if (obj == null)
return "";
String result = obj.toString(); return result.replace("\\", "\\\\").replace("_", "\\_").replace("%", "\\%"); /*if (result.startsWith("%") || result.startsWith("_")) {
result = "\\" + result;
} if (!"\\%".equals(result) && !"\\_".equals(result) && result.length() >= 2 && (result.endsWith("%") || result.endsWith("_"))) {
String tmp1 = result.substring(result.length() - 1, result.length());
String tmp2 = result.substring(0, result.length() - 1);
result = tmp2 + "\\" + tmp1;
}
return result;*/
} /**
* 获取GUID
* @return
*/
public static String GetGUID()
{
return UUID.randomUUID().toString().replace("-", "");
} }
最新文章
- couchDB视图
- [deviceone开发]-do_SegmentView和do_SlideView联动的示例
- 再次完善了 WASPCN for Matlab
- ubuntu git 使用
- Xamarin.Android 反复报 Please Download android_m2repository_rxx.zip 的解决办法
- UIScrollView,contentOffset,contentInsert的各自特点和区别?
- 大数加法之C语言函数法(只有正数版)
- 将Session放入Redis
- 编码注释coding: utf-8
- 图文浅析APK程序运行的过程
- ionic2自定义radio样式
- 把mysql脚本或其他数据库脚本导入Powerdesigner
- (4)java数据结构--集合类及其数据结构归纳-有大图
- jquery计算时间差(天、时、分、秒)并使用定时器实时获取
- eclipse打jar包解决第三方依赖包
- Qt 反射
- Hadoop2的Yarn和MapReduce2相关
- JS几个常用的工具函数
- oracle系统包——dbms_random用法
- [Go语言]从Docker源码学习Go——function和method