hutool中的字符串工具类

时间:2025-03-10 15:18:10
String a="db dg"; // 判断是否为空 // hasBlank 和 hasEmpty的区别 // hasBlank 判断是否为null或者空字符串和不可见的字符也所做是空 boolean b = StrUtil.hasBlank(a); // hasEmpty 只会判断 是否为null或者是空字符串 boolean b1 = StrUtil.hasEmpty(a); // 去掉指定的前缀 String c=a+"dddd"; String s = StrUtil.removePrefix(c, a); // 去掉指定的后缀 String d=""; String properties = StrUtil.removeSuffix(d, ".properties"); // 格式化字符串 // %s 代表一个字符串的占位 String format = String.format("你是%s", "小明"); // hutool中 格式化字符串 String template = "{}爱{},就像老鼠爱大米"; String format1 = StrUtil.format(template, "我", "你"); // 字符串反转 String e="abcd"; String reverse = StrUtil.reverse(e);