zoukankan      html  css  js  c++  java
  • 【Hutool】Hutool工具类之String工具——StrUtil

    类似的是commons-lang中的StringUtils

      空与非空的操作——经典的isBlank/isNotBlank、isEmpty/isNotEmpty

    isBlank()——是否为空白,空白的定义是null,"",不可见字符(如空格),

          镜像方法是isNotBlank()

          相关方法是hasBlank()——字符串列表是否有空白字符串;

              isAllBlank()——给定字符串列表是否全为空白

    isEmpty()——是否为空,空的定义是null,""

          镜像方法是isNotEmpty()

          相关方法是nullToEmpty()——给定字符串为空时返回"";镜像方法是emptyToNull()

              nullToDefault()——给定字符串为空null时返回默认字符串,否则返回本身

              hasEmpty/isAllEmpty()——类同isBlank()的,不再赘述

      指定字符开头或结尾

    startWith()——是否以指定字符或者指定字符串开头

           相关方法是startWithIgnoreCase()——忽略大小写

                  startWithAny()——以任意字符串开始

    endWith()——与上述的镜像方法,不再赘述

    containsIgnoreCase()——忽略大小写的包含

       去掉指定前后缀

    removeSuffix()——除指定后缀

              示例:String fileName = StrUtil.removeSuffix("pretty_girl.jpg", ".jpg")

    removePrefix——镜像方法,不再赘述

    上述方法的IgnoreCase忽略大小写方法不再赘述

      模板操作——类似slf4j的占位符进行字符串拼接

      直接使用官网文档的例子,简洁明了:

        String template = "{}爱{},就像老鼠爱大米";

        String str = StrUtil.format(template, "我", "你"); //str -> 我爱你,就像老鼠爱大米

  • 相关阅读:
    论文笔记系列-DARTS: Differentiable Architecture Search
    Win10安装TensorFlow1.9-GPU版本
    论文笔记系列-Efficient Neural Architecture Search via Parameter Sharing
    论文笔记模板
    无偏估计
    【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
    Python学习札记(十三) Function3 函数参数二
    LeetCode Add Two Numbers
    Python学习札记(十二) Function3 函数参数一
    Python学习札记(十一) Function2 函数定义
  • 原文地址:https://www.cnblogs.com/jiangbei/p/7726313.html
Copyright © 2011-2022 走看看