hutool 字符串工具类
//字符串工具类@Testpublicvoidtest13(){//判断空,空字符串,以及空格 isempty不能判断空格String a=" ";if(StrUtil.isBlank(a)){System.out.println("dddd");}//去除后缀String b="j.a.txt";Console.log(StrUtil.removeSuffix(b,".txt"));// j.a
·
//字符串工具类
@Test
public void test13(){
//判断空,空字符串,以及空格 isempty不能判断空格
String a=" ";
if(StrUtil.isBlank(a)){
System.out.println("dddd");
}
//去除后缀
String b="j.a.txt";
Console.log(StrUtil.removeSuffix(b,".txt"));// j.a
Console.log(StrUtil.removePrefix(b,"j."));// a.txt
// 截取字符串
String str = "abcdefgh";
String strSub1 = StrUtil.sub(str, 2, 3); //strSub1 -> c
String strSub2 = StrUtil.sub(str, 2, -3); //strSub2 -> cde
String strSub3 = StrUtil.sub(str, 3, 2); //strSub2 -> c
//format方法 牛逼拼接
String template = "{}love{}";
Console.log(StrUtil.format(template, "我", "你")); //str -> 我爱你,就像老鼠爱大米
//HexUtil就是将字符串或byte数组与16进制表示转换的工具类
String strs = "我是一个字符串";
String hex = HexUtil.encodeHexStr(strs, CharsetUtil.CHARSET_UTF_8);
//hex是:
//e68891e698afe4b880e4b8aae5ad97e7aca6e4b8b2
String decodedStr = HexUtil.decodeHexStr(hex);
//解码后与str相同
}
更多推荐
已为社区贡献2条内容
所有评论(0)