Class CharsKit

java.lang.Object
org.aoju.bus.core.toolkit.CharsKit
Direct Known Subclasses:
StringKit

public class CharsKit extends Object
字符工具类 部分工具来自于Apache
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • CharsKit

      public CharsKit()
  • Method Details

    • isAscii

      public static boolean isAscii(char ch)
      是否为ASCII字符,ASCII字符位于0~127之间
         CharKit.isAscii('a')  = true
         CharKit.isAscii('A')  = true
         CharKit.isAscii('3')  = true
         CharKit.isAscii('-')  = true
         CharKit.isAscii('\n') = true
         CharKit.isAscii('©') = false
       
      Parameters:
      ch - 被检查的字符处
      Returns:
      true表示为ASCII字符, ASCII字符位于0~127之间
    • isAsciiPrintable

      public static boolean isAsciiPrintable(char ch)
      是否为可见ASCII字符,可见字符位于32~126之间
         CharKit.isAsciiPrintable('a')  = true
         CharKit.isAsciiPrintable('A')  = true
         CharKit.isAsciiPrintable('3')  = true
         CharKit.isAsciiPrintable('-')  = true
         CharKit.isAsciiPrintable('\n') = false
         CharKit.isAsciiPrintable('©') = false
       
      Parameters:
      ch - 被检查的字符处
      Returns:
      true表示为ASCII可见字符, 可见字符位于32~126之间
    • isAsciiControl

      public static boolean isAsciiControl(char ch)
      是否为ASCII控制符(不可见字符),控制符位于0~31和127
         CharKit.isAsciiControl('a')  = false
         CharKit.isAsciiControl('A')  = false
         CharKit.isAsciiControl('3')  = false
         CharKit.isAsciiControl('-')  = false
         CharKit.isAsciiControl('\n') = true
         CharKit.isAsciiControl('©') = false
       
      Parameters:
      ch - 被检查的字符
      Returns:
      true表示为控制符, 控制符位于0~31和127
    • isLetter

      public static boolean isLetter(char ch)
      判断是否为字母(包括大写字母和小写字母) 字母包括A~Z和a~z
         CharKit.isLetter('a')  = true
         CharKit.isLetter('A')  = true
         CharKit.isLetter('3')  = false
         CharKit.isLetter('-')  = false
         CharKit.isLetter('\n') = false
         CharKit.isLetter('©') = false
       
      Parameters:
      ch - 被检查的字符
      Returns:
      true表示为字母(包括大写字母和小写字母)字母包括A~Z和a~z
    • isLetterUpper

      public static boolean isLetterUpper(char ch)
      判断是否为大写字母,大写字母包括A~Z
         CharKit.isLetterUpper('a')  = false
         CharKit.isLetterUpper('A')  = true
         CharKit.isLetterUpper('3')  = false
         CharKit.isLetterUpper('-')  = false
         CharKit.isLetterUpper('\n') = false
         CharKit.isLetterUpper('©') = false
       
      Parameters:
      ch - 被检查的字符
      Returns:
      true表示为大写字母, 大写字母包括A~Z
    • isLetterLower

      public static boolean isLetterLower(char ch)
      检查字符是否为小写字母,小写字母指a~z
         CharKit.isLetterLower('a')  = true
         CharKit.isLetterLower('A')  = false
         CharKit.isLetterLower('3')  = false
         CharKit.isLetterLower('-')  = false
         CharKit.isLetterLower('\n') = false
         CharKit.isLetterLower('©') = false
       
      Parameters:
      ch - 被检查的字符
      Returns:
      true表示为小写字母, 小写字母指a~z
    • isNumber

      public static boolean isNumber(char ch)
      检查是否为数字字符,数字字符指0~9
         CharKit.isNumber('a')  = false
         CharKit.isNumber('A')  = false
         CharKit.isNumber('3')  = true
         CharKit.isNumber('-')  = false
         CharKit.isNumber('\n') = false
         CharKit.isNumber('©') = false
       
      Parameters:
      ch - 被检查的字符
      Returns:
      true表示为数字字符, 数字字符指0~9
    • isHexChar

      public static boolean isHexChar(char c)
      是否为16进制规范的字符,判断是否为如下字符
       1. 0~9
       2. a~f
       4. A~F
       
      Parameters:
      c - 字符
      Returns:
      是否为16进制规范的字符
    • isLetterOrNumber

      public static boolean isLetterOrNumber(char ch)
      是否为字母或数字,包括A~Z、a~z、0~9
         CharKit.isLetterOrNumber('a')  = true
         CharKit.isLetterOrNumber('A')  = true
         CharKit.isLetterOrNumber('3')  = true
         CharKit.isLetterOrNumber('-')  = false
         CharKit.isLetterOrNumber('\n') = false
         CharKit.isLetterOrNumber('©') = false
       
      Parameters:
      ch - 被检查的字符
      Returns:
      true表示为字母或数字, 包括A~Z、a~z、0~9
    • isCharClass

      public static boolean isCharClass(Class<?> clazz)
      给定类名是否为字符类,字符类包括:
       Character.class
       char.class
       
      Parameters:
      clazz - 被检查的类
      Returns:
      true表示为字符类
    • isChar

      public static boolean isChar(Object value)
      给定对象对应的类是否为字符类,字符类包括:
       Character.class
       char.class
       
      Parameters:
      value - 被检查的对象
      Returns:
      true表示为字符类
    • isBlankChar

      public static boolean isBlankChar(char c)
      是否空白符 空白符包括空格、制表符、全角空格和不间断空格
      Parameters:
      c - 字符
      Returns:
      是否空白符
      See Also:
    • isBlankChar

      public static boolean isBlankChar(int c)
      是否空白符 空白符包括空格、制表符、全角空格和不间断空格
      Parameters:
      c - 字符
      Returns:
      是否空白符
      See Also:
    • isBlank

      public static boolean isBlank(CharSequence text)
      字符串是否为空白,空白的定义如下:
      1. null
      2. 空字符串:""
      3. 空格、全角空格、制表符、换行符,等不可见字符
      例:
      • StringKit.isBlank(null) // true
      • StringKit.isBlank("") // true
      • StringKit.isBlank(" \t\n") // true
      • StringKit.isBlank("abc") // false
      注意:该方法与 isEmpty(CharSequence) 的区别是: 该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢 建议:
      Parameters:
      text - 被检测的字符串
      Returns:
      若为空白,则返回 true
      See Also:
    • isNotBlank

      public static boolean isNotBlank(CharSequence text)
      字符串是否为非空白,非空白的定义如下:
      1. 不为 null
      2. 不为空字符串:""
      3. 不为空格、全角空格、制表符、换行符,等不可见字符
      例:
      • StringKit.isNotBlank(null) // false
      • StringKit.isNotBlank("") // false
      • StringKit.isNotBlank(" \t\n") // false
      • StringKit.isNotBlank("abc") // true
      注意:该方法与 isNotEmpty(CharSequence) 的区别是: 该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢 建议:仅对于客户端(或第三方接口)传入的参数使用该方法
      Parameters:
      text - 被检测的字符串
      Returns:
      是否为非空
      See Also:
    • isNoneBlank

      public static boolean isNoneBlank(CharSequence... texts)
      检查是否没有字符序列为空("")、空字符或仅为空格
       StringKit.isNoneBlank(null)             = false
       StringKit.isNoneBlank(null, "foo")      = false
       StringKit.isNoneBlank(null, null)       = false
       StringKit.isNoneBlank("", "bar")        = false
       StringKit.isNoneBlank("bob", "")        = false
       StringKit.isNoneBlank("  bob  ", null)  = false
       StringKit.isNoneBlank(" ", "bar")       = false
       StringKit.isNoneBlank(new String[] {})  = true
       StringKit.isNoneBlank(new String[]{""}) = false
       StringKit.isNoneBlank("foo", "bar")     = true
       
      Parameters:
      texts - 要检查的字符串可以为null或空
      Returns:
      所有字符序列都不为空或null或仅为空格
    • isAnyBlank

      public static boolean isAnyBlank(CharSequence... texts)
      检查任何一个字符序列是否为空(""),或为空,或仅为空白
       StringKit.isAnyBlank((String) null)    = true
       StringKit.isAnyBlank((String[]) null)  = false
       StringKit.isAnyBlank(null, "foo")      = true
       StringKit.isAnyBlank(null, null)       = true
       StringKit.isAnyBlank("", "bar")        = true
       StringKit.isAnyBlank("bob", "")        = true
       StringKit.isAnyBlank("  bob  ", null)  = true
       StringKit.isAnyBlank(" ", "bar")       = true
       StringKit.isAnyBlank(new String[] {})  = false
       StringKit.isAnyBlank(new String[]{""}) = true
       StringKit.isAnyBlank("foo", "bar")     = false
       
      Parameters:
      texts - 要检查的字符序列可以为空或空
      Returns:
      如果任何一个字符序列是空的,或者是空的,或者只有空白
    • isAllBlank

      public static boolean isAllBlank(CharSequence... texts)
      指定字符串数组中的元素,是否全部为空字符串 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true 例:
      • StringKit.isAllBlank() // true
      • StringKit.isAllBlank("", null, " ") // true
      • StringKit.isAllBlank("123", " ") // false
      • StringKit.isAllBlank("123", "abc") // false
      注意:该方法与 hasBlank(CharSequence...) 的区别在于:
      • hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...
      • isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...
      Parameters:
      texts - 字符串列表
      Returns:
      所有字符串是否为空白
    • isEmpty

      public static boolean isEmpty(CharSequence text)
      字符串是否为空,空的定义如下:
      1. null
      2. 空字符串:""
      例:
      • StringKit.isEmpty(null) // true
      • StringKit.isEmpty("") // true
      • StringKit.isEmpty(" \t\n") // false
      • StringKit.isEmpty("abc") // false
      注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符 建议:
      Parameters:
      text - 被检测的字符串
      Returns:
      是否为空
      See Also:
    • isNotEmpty

      public static boolean isNotEmpty(CharSequence text)
      字符串是否为非空白,非空白的定义如下:
      1. 不为 null
      2. 不为空字符串:""
      例:
      • StringKit.isNotEmpty(null) // false
      • StringKit.isNotEmpty("") // false
      • StringKit.isNotEmpty(" \t\n") // true
      • StringKit.isNotEmpty("abc") // true
      注意:该方法与 isNotBlank(CharSequence) 的区别是:该方法不校验空白字符 建议:该方法建议用于工具类或任何可以预期的方法参数的校验中
      Parameters:
      text - 被检测的字符串
      Returns:
      是否为非空
      See Also:
    • isAllEmpty

      public static boolean isAllEmpty(CharSequence... texts)
      指定字符串数组中的元素,是否全部为空字符串 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true 例:
      • StringKit.isAllEmpty() // true
      • StringKit.isAllEmpty("", null) // true
      • StringKit.isAllEmpty("123", "") // false
      • StringKit.isAllEmpty("123", "abc") // false
      • StringKit.isAllEmpty(" ", "\t", "\n") // false
      注意:该方法与 hasEmpty(CharSequence...) 的区别在于:
      • hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...
      • isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
      Parameters:
      texts - 字符串列表
      Returns:
      所有字符串是否为空白
    • isAllNotEmpty

      public static boolean isAllNotEmpty(CharSequence... args)
      指定字符串数组中的元素,是否都不为空字符串 如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true 例:
      • StringKit.isAllNotEmpty() // false
      • StringKit.isAllNotEmpty("", null) // false
      • StringKit.isAllNotEmpty("123", "") // false
      • StringKit.isAllNotEmpty("123", "abc") // true
      • StringKit.isAllNotEmpty(" ", "\t", "\n") // true
      注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
      • isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
      • isAllNotEmpty(CharSequence...) 等价于 !isEmpty(...) && !isEmpty(...) && ...
      Parameters:
      args - 字符串数组
      Returns:
      所有字符串是否都不为为空白
    • isAllNotBlank

      public static boolean isAllNotBlank(CharSequence... args)
      是否存都不为null或空对象或空白符的对象,通过hasBlank(CharSequence...) 判断元素
      Parameters:
      args - 被检查的对象,一个或者多个
      Returns:
      是否都不为空
    • isNullOrUndefined

      public static boolean isNullOrUndefined(CharSequence text)
      检查字符串是否为null、“null”、“undefined”
      Parameters:
      text - 被检查的字符串
      Returns:
      是否为null、“null”、“undefined”
    • isEmptyOrUndefined

      public static boolean isEmptyOrUndefined(CharSequence text)
      检查字符串是否为null、“”、“null”、“undefined”
      Parameters:
      text - 被检查的字符串
      Returns:
      是否为null、“”、“null”、“undefined”
    • isBlankOrUndefined

      public static boolean isBlankOrUndefined(CharSequence text)
      检查字符串是否为null、空白串、“null”、“undefined”
      Parameters:
      text - 被检查的字符串
      Returns:
      是否为null、空白串、“null”、“undefined”
    • hasBlank

      public static boolean hasBlank(CharSequence... texts)
      指定字符串数组中,是否包含空字符串 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true 例:
      • StringKit.hasBlank() // true
      • StringKit.hasBlank("", null, " ") // true
      • StringKit.hasBlank("123", " ") // true
      • StringKit.hasBlank("123", "abc") // false
      注意:该方法与 isAllBlank(CharSequence...) 的区别在于:
      • hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...
      • isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...
      Parameters:
      texts - 字符串列表
      Returns:
      是否包含空字符串
    • isAllCharMatch

      public static boolean isAllCharMatch(CharSequence value, Matcher<Character> matcher)
      字符串的每一个字符是否都与定义的匹配器匹配
      Parameters:
      value - 字符串
      matcher - 匹配器
      Returns:
      是否全部匹配
    • emptyIfNull

      public static String emptyIfNull(CharSequence text)
      当给定字符串为null时,转换为Empty
      Parameters:
      text - 被检查的字符串
      Returns:
      原字符串或者空串
      See Also:
    • emptyToNull

      public static String emptyToNull(CharSequence text)
      当给定字符串为空字符串时,转换为null
      Parameters:
      text - 被转换的字符串
      Returns:
      转换后的字符串
    • hasEmpty

      public static boolean hasEmpty(CharSequence... texts)
      是否包含空字符串 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true 例:
      • StringKit.hasEmpty() // true
      • StringKit.hasEmpty("", null) // true
      • StringKit.hasEmpty("123", "") // true
      • StringKit.hasEmpty("123", "abc") // false
      • StringKit.hasEmpty(" ", "\t", "\n") // false
      注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
      • hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...
      • isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
      Parameters:
      texts - 字符串列表
      Returns:
      是否包含空字符串
    • isEmoji

      public static boolean isEmoji(char c)
      判断是否为emoji表情符
      Parameters:
      c - 字符
      Returns:
      是否为emoji
    • equals

      public static boolean equals(char c1, char c2, boolean ignoreCase)
      比较两个字符是否相同
      Parameters:
      c1 - 字符1
      c2 - 字符2
      ignoreCase - 是否忽略大小写
      Returns:
      是否相同
    • count

      public static int count(CharSequence content, CharSequence strForSearch)
      统计指定内容中包含指定字符串的数量 参数为 null 或者 "" 返回 0.
       count(null, *)       = 0
       count("", *)         = 0
       count("abba", null)  = 0
       count("abba", "")    = 0
       count("abba", "a")   = 2
       count("abba", "ab")  = 1
       count("abba", "xxx") = 0
       
      Parameters:
      content - 被查找的字符串
      strForSearch - 需要查找的字符串
      Returns:
      查找到的个数
    • count

      public static int count(CharSequence content, char charForSearch)
      统计指定内容中包含指定字符的数量
      Parameters:
      content - 内容
      charForSearch - 被统计的字符
      Returns:
      包含数量
    • isFileSeparator

      public static boolean isFileSeparator(char c)
      是否为Windows或者Linux(Unix)文件分隔符 Windows平台下分隔符为\,Linux(Unix)为/
      Parameters:
      c - 字符
      Returns:
      是否为Windows或者Linux(Unix)文件分隔符
    • compare

      public static int compare(char x, char y)
      对两个char值进行数值比较
      Parameters:
      x - char
      y - char 如果x == y返回值0; 如果x < y值小于0;和 如果x > y
      Returns:
      the int
    • getChars

      public static char[] getChars(byte[] bytes)
    • byteToChar

      public static char byteToChar(byte[] b)
      byte转car
      Parameters:
      b - 字节信息
      Returns:
      char
    • toCloseChar

      public static char toCloseChar(char c)
      将字母、数字转换为带圈的字符:
           '1' -》 '①'
           'A' -》 'Ⓐ'
           'a' -》 'ⓐ'
       
      获取带圈数字 /封闭式字母数字 ,从1-20,超过1-20报错 0 1 2 3 4 5 6 7 8 9 A B C D E F U+246x ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ U+247x ⑰ ⑱ ⑲ ⑳ ⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿ U+248x ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ U+249x ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ ⒜ ⒝ ⒞ ⒟ U+24Ax ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ U+24Bx ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ U+24Cx Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ U+24Dx ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ U+24Ex ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ ⓪ ⓫ ⓬ ⓭ ⓮ ⓯ U+24Fx ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿
      Parameters:
      c - 被转换的字符,如果字符不支持转换,返回原字符
      Returns:
      转换后的字符
    • toCloseByNumber

      public static char toCloseByNumber(int number)
      封闭式字符,英文:Enclosed Alphanumerics 将[1-20]数字转换为带圈的字符:
           1 -》 '①'
           12 -》 '⑫'
           20 -》 '⑳'
       
      Parameters:
      number - 被转换的数字
      Returns:
      转换后的字符
    • startWithNumber

      public static boolean startWithNumber(CharSequence text)
      字符串是否以(数字)开始
      Parameters:
      text - 字符串
      Returns:
      是否数字开始
    • startWithGeneral

      public static boolean startWithGeneral(CharSequence text)
      字符串是否以(英文字母 、数字和下划线)开始
      Parameters:
      text - 字符串
      Returns:
      是否英文字母 、数字和下划线开始
    • startWithWord

      public static boolean startWithWord(CharSequence text)
      字符串是否以(字母)开始
      Parameters:
      text - 字符串
      Returns:
      是否字母开始
    • startWithChinese

      public static boolean startWithChinese(CharSequence text)
      字符串是否以(中文汉字)开始
      Parameters:
      text - 字符串
      Returns:
      是否中文汉字开始
    • isCharEquals

      public static boolean isCharEquals(CharSequence str)
      检查给定字符串的所有字符是否都一样
      Parameters:
      str - 字符出啊
      Returns:
      给定字符串的所有字符是否都一样
    • normalize

      public static String normalize(CharSequence str)
      对字符串归一化处理,如 "Á" 可以使用 "u00C1"或 "u0041u0301"表示,实际测试中两个字符串并不equals 因此使用此方法归一为一种表示形式,默认按照W3C通常建议的,在NFC中交换文本。
      Parameters:
      str - 归一化的字符串
      Returns:
      归一化后的字符串
      See Also:
    • fixLength

      public static String fixLength(CharSequence str, char fixedChar, int length)
      在给定字符串末尾填充指定字符,以达到给定长度 如果字符串本身的长度大于等于length,返回原字符串
      Parameters:
      str - 字符串
      fixedChar - 补充的字符
      length - 补充到的长度
      Returns:
      补充后的字符串
    • trim

      public static String trim(CharSequence text)
      字符串去空格
      Parameters:
      text - 原始字符串
      Returns:
      返回字符串
    • trim

      public static String trim(CharSequence text, int mode)
      除去字符串头尾部的空白符,如果字符串是null,依然返回null
      Parameters:
      text - 要处理的字符串
      mode - -1去除开始位置,0全部去除, 1去除结束位置
      Returns:
      除去指定字符后的的字符串, 如果原字串为null, 则返回null
    • trim

      public static String trim(CharSequence text, int mode, Predicate<Character> predicate)
      按照断言,除去字符串头尾部的断言为真的字符,如果字符串是null,依然返回null
      Parameters:
      text - 要处理的字符串
      mode - -1表示trimStart,0表示trim全部, 1表示trimEnd
      predicate - 断言是否过掉字符,返回true表述过滤掉,false表示不过滤
      Returns:
      除去指定字符后的的字符串,如果原字串为null,则返回null
    • trimToNull

      public static String trimToNull(CharSequence text)
      删除字符串两端的空白字符(char <= 32),如果字符串在修剪后为空("") 或者如果字符串为null,则返回null
       StringKit.trimToNull(null)           = null
       StringKit.trimToNull("")             = null
       StringKit.trimToNull("     ")        = null
       StringKit.trimToNull("abc")          = "abc"
       StringKit.trimToEmpty("    abc    ") = "abc"
       
      Parameters:
      text - 字符串
      Returns:
      去除两边空白符后的字符串, 如果为空返回null
    • removePreAndLowerFirst

      public static String removePreAndLowerFirst(CharSequence text, int preLength)
      去掉首部指定长度的字符串并将剩余字符串首字母小写 例如:text=setName, preLength=3 = return name
      Parameters:
      text - 被处理的字符串
      preLength - 去掉的长度
      Returns:
      处理后的字符串, 不符合规范返回null
    • removePreAndLowerFirst

      public static String removePreAndLowerFirst(CharSequence text, CharSequence prefix)
      去掉首部指定长度的字符串并将剩余字符串首字母小写 例如:text=setName, prefix=set = return name
      Parameters:
      text - 被处理的字符串
      prefix - 前缀
      Returns:
      处理后的字符串, 不符合规范返回null
    • removePrefix

      public static String removePrefix(CharSequence text, CharSequence prefix)
      去掉指定前缀
      Parameters:
      text - 字符串
      prefix - 前缀
      Returns:
      切掉后的字符串, 若前缀不是 preffix, 返回原字符串
    • removePrefixIgnoreCase

      public static String removePrefixIgnoreCase(CharSequence text, CharSequence prefix)
      忽略大小写去掉指定前缀
      Parameters:
      text - 字符串
      prefix - 前缀
      Returns:
      切掉后的字符串, 若前缀不是 prefix, 返回原字符串
    • removeSuffix

      public static String removeSuffix(CharSequence text, CharSequence suffix)
      去掉指定后缀
      Parameters:
      text - 字符串
      suffix - 后缀
      Returns:
      切掉后的字符串, 若后缀不是 suffix, 返回原字符串
    • removeSufAndLowerFirst

      public static String removeSufAndLowerFirst(CharSequence str, CharSequence suffix)
      去掉指定后缀,并小写首字母
      Parameters:
      str - 字符串
      suffix - 后缀
      Returns:
      切掉后的字符串,若后缀不是 suffix, 返回原字符串
    • removeSuffixIgnoreCase

      public static String removeSuffixIgnoreCase(CharSequence str, CharSequence suffix)
      忽略大小写去掉指定后缀
      Parameters:
      str - 字符串
      suffix - 后缀
      Returns:
      切掉后的字符串,若后缀不是 suffix, 返回原字符串
    • upperFirstAndAddPre

      public static String upperFirstAndAddPre(CharSequence text, String preString)
      原字符串首字母大写并在其首部添加指定字符串 例如:text=name, preString=get = return getName
      Parameters:
      text - 被处理的字符串
      preString - 添加的首部
      Returns:
      处理后的字符串
    • upperFirst

      public static String upperFirst(CharSequence text)
      大写首字母 例如:text = name, return Name
      Parameters:
      text - 字符串
      Returns:
      字符串
    • lowerFirst

      public static String lowerFirst(CharSequence text)
      小写首字母 例如:text = Name, return name
      Parameters:
      text - 字符串
      Returns:
      字符串
    • toUnderlineCase

      public static String toUnderlineCase(CharSequence camelCaseStr)
      将驼峰式命名的字符串转换为下划线方式 如果转换前的驼峰式命名的字符串为空,则返回空字符串 例如:HelloWorld= hello_world
      Parameters:
      camelCaseStr - 转换前的驼峰式命名的字符串
      Returns:
      转换后下划线大写方式命名的字符串
    • toSymbolCase

      public static String toSymbolCase(CharSequence text, char symbol)
      将驼峰式命名的字符串转换为使用符号连接方式 如果转换前的驼峰式命名的字符串为空,则返回空字符串
      Parameters:
      text - 转换前的驼峰式命名的字符串,也可以为符号连接形式
      symbol - 连接符
      Returns:
      转换后符号连接方式命名的字符串
    • toCamelCase

      public static String toCamelCase(CharSequence text)
      将下划线方式命名的字符串转换为驼峰式 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串 例如:hello_world = helloWorld
      Parameters:
      text - 转换前的下划线大写方式命名的字符串
      Returns:
      转换后的驼峰式命名的字符串
    • toCamelCase

      public static String toCamelCase(CharSequence name, char symbol)
      将连接符方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串 例如:hello_world = helloWorld; hello-world = helloWorld
      Parameters:
      name - 转换前的下划线大写方式命名的字符串
      symbol - 连接符
      Returns:
      转换后的驼峰式命名的字符串
      See Also:
    • removeAll

      public static String removeAll(CharSequence text, CharSequence strToRemove)
      移除字符串中所有给定字符串 例:removeAll("aa-bb-cc-dd", "-") - aabbccdd
      Parameters:
      text - 字符串
      strToRemove - 被移除的字符串
      Returns:
      移除后的字符串
    • removeAll

      public static String removeAll(CharSequence text, char... chars)
      去除字符串中指定的多个字符,如有多个则全部去除
      Parameters:
      text - 字符串
      chars - 字符列表
      Returns:
      去除后的字符
    • removeAny

      public static String removeAny(CharSequence text, CharSequence... strsToRemove)
      移除字符串中所有给定字符串,当某个字符串出现多次,则全部移除 例:removeAny("aa-bb-cc-dd", "a", "b") - --cc-dd
      Parameters:
      text - 字符串
      strsToRemove - 被移除的字符串
      Returns:
      移除后的字符串
    • format

      public static String format(CharSequence template, Map<?,?> args)
      格式化文本
      Parameters:
      template - 文本模板,被替换的部分用 {key} 表示
      args - 参数值对
      Returns:
      格式化后的文本
    • format

      public static String format(CharSequence template, Object... args)
      格式化文本, {} 表示占位符 此方法只是简单将占位符 {} 按照顺序替换为参数 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用:format("this is {} for {}", "a", "b") = this is a for b 转义{}: format("this is \\{} for {}", "a", "b") = this is \{} for a 转义\: format("this is \\\\{} for {}", "a", "b") = this is \a for b
      Parameters:
      template - 文本模板,被替换的部分用 {} 表示,如果模板为null,返回"null"
      args - 参数值
      Returns:
      格式化后的文本,如果模板为null,返回"null"
    • format

      public static String format(CharSequence template, Map<?,?> map, boolean ignoreNull)
      格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) - aValue and bValue
      Parameters:
      template - 文本模板,被替换的部分用 {key} 表示
      map - 参数值对
      ignoreNull - 是否忽略 null 值,忽略则 null 值对应的变量不被替换,否则替换为""
      Returns:
      格式化后的文本
    • sub

      public static String sub(CharSequence text, int fromIndex, int toIndex)
      改进JDK subString index从0开始计算,最后一个字符为-1 如果from和to位置一样,返回 "" 如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length 如果经过修正的index中from大于to,则互换 abcdefgh 2 3 = c abcdefgh 2 -3 = cde
      Parameters:
      text - String
      fromIndex - 开始的index(包括)
      toIndex - 结束的index(不包括)
      Returns:
      字串
    • subPre

      public static String subPre(CharSequence string, int toIndex)
      切割指定位置之前部分的字符串
      Parameters:
      string - 字符串
      toIndex - 切割到的位置(不包括)
      Returns:
      切割后的剩余的前半部分字符串
    • subPreGbk

      public static String subPreGbk(CharSequence text, int len, CharSequence suffix)
      截取部分字符串,这里一个汉字的长度认为是2
      Parameters:
      text - 字符串
      len - bytes切割到的位置(包含)
      suffix - 切割后加上后缀
      Returns:
      切割后的字符串
    • subPreGbk

      public static String subPreGbk(CharSequence text, int len, boolean halfUp)
      截取部分字符串,这里一个汉字的长度认为是2 可以自定义halfUp,如len为10,如果截取后最后一个字符是半个字符,true表示保留,则长度是11,否则长度9
      Parameters:
      text - 字符串
      len - bytes切割到的位置(包含)
      halfUp - 遇到截取一半的GBK字符,是否保留。
      Returns:
      切割后的字符串
    • subSuf

      public static String subSuf(CharSequence string, int fromIndex)
      切割指定位置之后部分的字符串
      Parameters:
      string - 字符串
      fromIndex - 切割开始的位置(包括)
      Returns:
      切割后后剩余的后半部分字符串
    • subBefore

      public static String subBefore(CharSequence string, CharSequence separator, boolean isLastSeparator)
      截取分隔字符串之前的字符串,不包括分隔字符串 如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串 如果分隔字符串为空串"",则返回空串,如果分隔字符串未找到,返回原字符串,举例如下:
       StringKit.subBefore(null, *)      = null
       StringKit.subBefore("", *)        = ""
       StringKit.subBefore("abc", "a")   = ""
       StringKit.subBefore("abcba", "b") = "a"
       StringKit.subBefore("abc", "c")   = "ab"
       StringKit.subBefore("abc", "d")   = "abc"
       StringKit.subBefore("abc", "")    = ""
       StringKit.subBefore("abc", null)  = "abc"
       
      Parameters:
      string - 被查找的字符串
      separator - 分隔字符串(不包括)
      isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个
      Returns:
      切割后的字符串
    • subBefore

      public static String subBefore(CharSequence string, char separator, boolean isLastSeparator)
      截取分隔字符串之前的字符串,不包括分隔字符串 如果给定的字符串为空串(null或"")或者分隔字符串为null,返回原字符串 如果分隔字符串未找到,返回原字符串,举例如下:
       StringKit.subBefore(null, *)      = null
       StringKit.subBefore("", *)        = ""
       StringKit.subBefore("abc", 'a')   = ""
       StringKit.subBefore("abcba", 'b') = "a"
       StringKit.subBefore("abc", 'c')   = "ab"
       StringKit.subBefore("abc", 'd')   = "abc"
       
      Parameters:
      string - 被查找的字符串
      separator - 分隔字符串(不包括)
      isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个
      Returns:
      切割后的字符串
    • subAfter

      public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator)
      截取分隔字符串之后的字符串,不包括分隔字符串 如果给定的字符串为空串(null或""),返回原字符串 如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下:
       StringKit.subAfter(null, *)      = null
       StringKit.subAfter("", *)        = ""
       StringKit.subAfter(*, null)      = ""
       StringKit.subAfter("abc", "a")   = "bc"
       StringKit.subAfter("abcba", "b") = "cba"
       StringKit.subAfter("abc", "c")   = ""
       StringKit.subAfter("abc", "d")   = ""
       StringKit.subAfter("abc", "")    = "abc"
       
      Parameters:
      string - 被查找的字符串
      separator - 分隔字符串(不包括)
      isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个
      Returns:
      切割后的字符串
    • subAfter

      public static String subAfter(CharSequence string, char separator, boolean isLastSeparator)
      截取分隔字符串之后的字符串,不包括分隔字符串 如果给定的字符串为空串(null或""),返回原字符串 如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下:
       StringKit.subAfter(null, *)      = null
       StringKit.subAfter("", *)        = ""
       StringKit.subAfter("abc", 'a')   = "bc"
       StringKit.subAfter("abcba", 'b') = "cba"
       StringKit.subAfter("abc", 'c')   = ""
       StringKit.subAfter("abc", 'd')   = ""
       
      Parameters:
      string - 被查找的字符串
      separator - 分隔字符串(不包括)
      isLastSeparator - 是否查找最后一个分隔字符串(多次出现分隔字符串时选取最后一个),true为选取最后一个
      Returns:
      切割后的字符串
    • subBetween

      public static String subBetween(CharSequence text, CharSequence before, CharSequence after)
      截取指定字符串中间部分,不包括标识字符串
      Parameters:
      text - 被切割的字符串
      before - 截取开始的字符串标识
      after - 截取到的字符串标识
      Returns:
      截取后的字符串
    • subBetween

      public static String subBetween(String text, String before, String after)
      截取指定字符串中间部分,不包括标识字符串
       StringKit.subBetween("wx[b]yz", "[", "]")     = "b"
       StringKit.subBetween(null, *, *)              = null
       StringKit.subBetween(*, null, *)              = null
       StringKit.subBetween(*, *, null)              = null
       StringKit.subBetween("", "", "")              = ""
       StringKit.subBetween("", "", "]")             = null
       StringKit.subBetween("", "[", "]")            = null
       StringKit.subBetween("yabcz", "", "")         = ""
       StringKit.subBetween("yabcz", "y", "z")       = "abc"
       StringKit.subBetween("yabczyabcz", "y", "z")  = "abc"
       
      Parameters:
      text - 被切割的字符串
      before - 截取开始的字符串标识
      after - 截取到的字符串标识
      Returns:
      截取后的字符串
    • subBetween

      public static String subBetween(CharSequence text, CharSequence beforeAndAfter)
      截取指定字符串中间部分,不包括标识字符串
       StringKit.subBetween(null, *)            = null
       StringKit.subBetween("", "")             = ""
       StringKit.subBetween("", "tag")          = null
       StringKit.subBetween("tagabctag", null)  = null
       StringKit.subBetween("tagabctag", "")    = ""
       StringKit.subBetween("tagabctag", "tag") = "abc"
       
      Parameters:
      text - 被切割的字符串
      beforeAndAfter - 截取开始和结束的字符串标识
      Returns:
      截取后的字符串
    • subBetweenAll

      public static String[] subBetweenAll(CharSequence text, CharSequence prefix, CharSequence suffix)
      截取指定字符串多段中间部分,不包括标识字符串
       StringKit.subBetweenAll("wx[b]y[z]", "[", "]")                     = ["b","z"]
       StringKit.subBetweenAll(null, *, *)                            = []
       StringKit.subBetweenAll(*, null, *)                            = []
       StringKit.subBetweenAll(*, *, null)                            = []
       StringKit.subBetweenAll("", "", "")                            = []
       StringKit.subBetweenAll("", "", "]")                           = []
       StringKit.subBetweenAll("", "[", "]")                          = []
       StringKit.subBetweenAll("yabcz", "", "")                       = []
       StringKit.subBetweenAll("yabcz", "y", "z")                     = ["abc"]
       StringKit.subBetweenAll("yabczyabcz", "y", "z")                = ["abc","abc"]
       StringKit.subBetweenAll("[yabc[zy]abcz]", "[", "]");     = ["zy"]
       
      Parameters:
      text - 被切割的字符串
      prefix - 截取开始的字符串标识
      suffix - 截取到的字符串标识
      Returns:
      截取后的字符串
    • subBetweenAll

      public static String[] subBetweenAll(CharSequence text, CharSequence prefixAndSuffix)
      截取指定字符串多段中间部分,不包括标识字符串

      栗子:

       StringKit.subBetweenAll(null, *)                               = []
       StringKit.subBetweenAll(*, null)                               = []
       StringKit.subBetweenAll(*, *)                                      = []
       StringKit.subBetweenAll("", "")                                = []
       StringKit.subBetweenAll("", "#")                               = []
       StringKit.subBetweenAll("hello", "")                       = []
       StringKit.subBetweenAll("#hello#", "#")                    = ["hello"]
       StringKit.subBetweenAll("#hello# #world#!", "#")     = ["hello", "world"]
       StringKit.subBetweenAll("#hello# world#!", "#");     = ["hello"]
       
      Parameters:
      text - 被切割的字符串
      prefixAndSuffix - 截取开始和结束的字符串标识
      Returns:
      截取后的字符串
    • subByLength

      public static String subByLength(CharSequence text, int length)
      切割指定长度的后部分的字符串
       StringKit.subSufByLength("abcde", 3)      =    "cde"
       StringKit.subSufByLength("abcde", 0)      =    ""
       StringKit.subSufByLength("abcde", -5)     =    ""
       StringKit.subSufByLength("abcde", -1)     =    ""
       StringKit.subSufByLength("abcde", 5)      =    "abcde"
       StringKit.subSufByLength("abcde", 10)     =    "abcde"
       StringKit.subSufByLength(null, 3)         =     null
       
      Parameters:
      text - 字符串
      length - 切割长度
      Returns:
      切割后后剩余的后半部分字符串
    • equals

      public static boolean equals(CharSequence stra, CharSequence strb)
      比较两个字符串(大小写敏感)
       equals(null, null)   = true
       equals(null, "abc")  = false
       equals("abc", null)  = false
       equals("abc", "abc") = true
       equals("abc", "ABC") = false
       
      Parameters:
      stra - 要比较的字符串
      strb - 要比较的字符串
      Returns:
      如果两个字符串相同,或者都是null,则返回true
    • equals

      public static boolean equals(CharSequence stra, CharSequence strb, boolean ignoreCase)
      比较两个字符串是否相等
      Parameters:
      stra - 要比较的字符串
      strb - 要比较的字符串
      ignoreCase - 是否忽略大小写
      Returns:
      如果两个字符串相同,或者都是null,则返回true
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(CharSequence stra, CharSequence strb)
      比较两个字符串(大小写不敏感)
       equalsIgnoreCase(null, null)   = true
       equalsIgnoreCase(null, "abc")  = false
       equalsIgnoreCase("abc", null)  = false
       equalsIgnoreCase("abc", "abc") = true
       equalsIgnoreCase("abc", "ABC") = true
       
      Parameters:
      stra - 要比较的字符串
      strb - 要比较的字符串
      Returns:
      如果两个字符串相同,或者都是null,则返回true
    • equalsAnyIgnoreCase

      public static boolean equalsAnyIgnoreCase(CharSequence stra, CharSequence... strb)
      给定字符串是否与提供的中任一字符串相同(忽略大小写),相同则返回true,没有相同的返回false 如果参与比对的字符串列表为空,返回false
      Parameters:
      stra - 给定需要检查的字符串
      strb - 需要参与比对的字符串列表
      Returns:
      是否相同
    • equalsAny

      public static boolean equalsAny(CharSequence str1, CharSequence... texts)
      给定字符串是否与提供的中任一字符串相同,相同则返回true,没有相同的返回false 如果参与比对的字符串列表为空,返回false
      Parameters:
      str1 - 给定需要检查的字符串
      texts - 需要参与比对的字符串列表
      Returns:
      是否相同
    • equalsAny

      public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... texts)
      给定字符串是否与提供的中任一字符串相同,相同则返回true,没有相同的返回false 如果参与比对的字符串列表为空,返回false
      Parameters:
      str1 - 给定需要检查的字符串
      ignoreCase - 是否忽略大小写
      texts - 需要参与比对的字符串列表
      Returns:
      是否相同
    • indexOf

      public static int indexOf(CharSequence text, char searchChar)
      指定范围内查找指定字符
      Parameters:
      text - 字符串
      searchChar - 被查找的字符
      Returns:
      位置
    • indexOf

      public static int indexOf(CharSequence text, char searchChar, int start)
      指定范围内查找指定字符
      Parameters:
      text - 字符串
      searchChar - 被查找的字符
      start - 起始位置,如果小于0,从0开始查找
      Returns:
      位置
    • indexOf

      public static int indexOf(CharSequence text, char searchChar, int start, int end)
      指定范围内查找指定字符
      Parameters:
      text - 字符串
      searchChar - 被查找的字符
      start - 起始位置,如果小于0,从0开始查找
      end - 终止位置,如果超过text.length()则默认查找到字符串末尾
      Returns:
      位置
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(CharSequence text, CharSequence word)
      指定范围内查找字符串,忽略大小写
       StringKit.indexOfIgnoreCase(null, *, *)          = -1
       StringKit.indexOfIgnoreCase(*, null, *)          = -1
       StringKit.indexOfIgnoreCase("", "", 0)           = 0
       StringKit.indexOfIgnoreCase("aabaabaa", "A", 0)  = 0
       StringKit.indexOfIgnoreCase("aabaabaa", "B", 0)  = 2
       StringKit.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
       StringKit.indexOfIgnoreCase("aabaabaa", "B", 3)  = 5
       StringKit.indexOfIgnoreCase("aabaabaa", "B", 9)  = -1
       StringKit.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
       StringKit.indexOfIgnoreCase("aabaabaa", "", 2)   = 2
       StringKit.indexOfIgnoreCase("abc", "", 9)        = -1
       
      Parameters:
      text - 字符串
      word - 需要查找位置的字符串
      Returns:
      位置
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(CharSequence text, CharSequence word, int from)
      指定范围内查找字符串
       StringKit.indexOfIgnoreCase(null, *, *)          = -1
       StringKit.indexOfIgnoreCase(*, null, *)          = -1
       StringKit.indexOfIgnoreCase("", "", 0)           = 0
       StringKit.indexOfIgnoreCase("aabaabaa", "A", 0)  = 0
       StringKit.indexOfIgnoreCase("aabaabaa", "B", 0)  = 2
       StringKit.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1
       StringKit.indexOfIgnoreCase("aabaabaa", "B", 3)  = 5
       StringKit.indexOfIgnoreCase("aabaabaa", "B", 9)  = -1
       StringKit.indexOfIgnoreCase("aabaabaa", "B", -1) = 2
       StringKit.indexOfIgnoreCase("aabaabaa", "", 2)   = 2
       StringKit.indexOfIgnoreCase("abc", "", 9)        = -1
       
      Parameters:
      text - 字符串
      word - 需要查找位置的字符串
      from - 起始位置
      Returns:
      位置
    • indexOf

      public static int indexOf(CharSequence text, CharSequence word, int from, boolean ignoreCase)
      指定范围内反向查找字符串
      Parameters:
      text - 字符串,空则返回-1
      word - 需要查找位置的字符串,空则返回-1
      from - 起始位置(包含)
      ignoreCase - 是否忽略大小写
      Returns:
      位置
    • lastIndexOfIgnoreCase

      public static int lastIndexOfIgnoreCase(CharSequence text, CharSequence word)
      指定范围内查找字符串,忽略大小写
      Parameters:
      text - 字符串
      word - 需要查找位置的字符串
      Returns:
      位置
    • lastIndexOfIgnoreCase

      public static int lastIndexOfIgnoreCase(CharSequence text, CharSequence word, int from)
      指定范围内查找字符串,忽略大小写
      Parameters:
      text - 字符串
      word - 需要查找位置的字符串
      from - 起始位置,从后往前计数
      Returns:
      位置
    • lastIndexOf

      public static int lastIndexOf(CharSequence text, CharSequence word, int from, boolean ignoreCase)
      指定范围内查找字符串
      Parameters:
      text - 字符串
      word - 需要查找位置的字符串
      from - 起始位置,从后往前计数
      ignoreCase - 是否忽略大小写
      Returns:
      位置
    • splitToLong

      public static long[] splitToLong(CharSequence text, char separator)
      切分字符串为long数组
      Parameters:
      text - 被切分的字符串
      separator - 分隔符
      Returns:
      切分后long数组
    • splitToLong

      public static long[] splitToLong(CharSequence text, CharSequence separator)
      切分字符串为long数组
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符串
      Returns:
      切分后long数组
    • splitToInt

      public static int[] splitToInt(CharSequence text, char separator)
      切分字符串为int数组
      Parameters:
      text - 被切分的字符串
      separator - 分隔符
      Returns:
      切分后long数组
    • splitToInt

      public static int[] splitToInt(CharSequence text, CharSequence separator)
      切分字符串为int数组
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符串
      Returns:
      切分后long数组
    • splitToArray

      public static String[] splitToArray(CharSequence text, CharSequence separator)
      切分字符串,如果分隔符不存在则返回原字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符
      Returns:
      字符串
    • splitToArray

      public static String[] splitToArray(CharSequence text, char separator)
      切分字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      Returns:
      切分后的数组
    • splitToArray

      public static String[] splitToArray(CharSequence text, char separator, int limit)
      切分字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数
      Returns:
      切分后的数组
    • split

      public static List<String> split(CharSequence text, char separator)
      切分字符串 a#b#c =》 [a,b,c] a##b#c =》 [a,"",b,c]
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      Returns:
      切分后的集合
    • splitTrim

      public static List<String> splitTrim(CharSequence text, char separator)
      切分字符串,去除切分后每个元素两边的空白符,去除空白项
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      Returns:
      切分后的集合
    • splitTrim

      public static List<String> splitTrim(CharSequence text, CharSequence separator)
      切分字符串,去除切分后每个元素两边的空白符,去除空白项
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      Returns:
      切分后的集合
    • splitTrim

      public static List<String> splitTrim(CharSequence text, char separator, int limit)
      切分字符串,去除切分后每个元素两边的空白符,去除空白项
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数,-1不限制
      Returns:
      切分后的集合
    • splitTrim

      public static List<String> splitTrim(CharSequence text, CharSequence separator, int limit)
      切分字符串,去除切分后每个元素两边的空白符,去除空白项
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数,-1不限制
      Returns:
      切分后的集合
    • split

      public static String[] split(CharSequence text, int len)
      根据给定长度,将给定字符串截取为多个部分
      Parameters:
      text - 字符串
      len - 每一个小节的长度
      Returns:
      截取后的字符串数组
      See Also:
    • split

      public static List<String> split(CharSequence text, CharSequence separator)
      切分字符串,如果分隔符不存在则返回原字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符
      Returns:
      字符串
    • split

      public static List<String> split(CharSequence text, char separator, int limit)
      切分字符串,不去除切分后每个元素两边的空白符,不去除空白项
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数,-1不限制
      Returns:
      切分后的集合
    • split

      public static List<String> split(CharSequence text, char separator, boolean isTrim, boolean ignoreEmpty)
      切分字符串,不限制分片数量
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      isTrim - 是否去除切分字符串后每个元素两边的空格
      ignoreEmpty - 是否忽略空串
      Returns:
      切分后的集合
    • split

      public static List<String> split(CharSequence text, CharSequence separator, boolean isTrim, boolean ignoreEmpty)
      切分字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      isTrim - 是否去除切分字符串后每个元素两边的空格
      ignoreEmpty - 是否忽略空串
      Returns:
      切分后的集合
    • split

      public static List<String> split(CharSequence text, char separator, int limit, boolean isTrim, boolean ignoreEmpty)
      切分字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数,-1不限制
      isTrim - 是否去除切分字符串后每个元素两边的空格
      ignoreEmpty - 是否忽略空串
      Returns:
      切分后的集合
    • split

      public static List<String> split(CharSequence text, CharSequence separator, int limit, boolean isTrim, boolean ignoreEmpty)
      切分字符串
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数,-1不限制
      isTrim - 是否去除切分字符串后每个元素两边的空格
      ignoreEmpty - 是否忽略空串
      Returns:
      切分后的集合
    • split

      public static <R> List<R> split(CharSequence text, char separator, int limit, boolean ignoreEmpty, Function<String,R> mapping)
      切分字符串
      Type Parameters:
      R - 切分后元素类型
      Parameters:
      text - 被切分的字符串
      separator - 分隔符字符
      limit - 限制分片数,-1不限制
      ignoreEmpty - 是否忽略空串
      mapping - 切分后的字符串元素的转换方法
      Returns:
      切分后的集合,元素类型是经过 mapping 转换后的
    • subCodePoint

      public static String subCodePoint(CharSequence text, int fromIndex, int toIndex)
      通过CodePoint截取字符串,可以截断Emoji
      Parameters:
      text - string
      fromIndex - 开始的index(包括)
      toIndex - 结束的index(不包括)
      Returns:
      字串
    • nullToEmpty

      public static String nullToEmpty(CharSequence text)
      当给定字符串为null时,转换为Empty
      Parameters:
      text - 被转换的字符串
      Returns:
      转换后的字符串
    • nullToDefault

      public static String nullToDefault(CharSequence text, String defaultStr)
      如果字符串是null,则返回指定默认字符串,否则返回字符串本身。
       nullToDefault(null, "default")  = "default"
       nullToDefault("", "default")    = ""
       nullToDefault("  ", "default")  = "  "
       nullToDefault("bat", "default") = "bat"
       
      Parameters:
      text - 要转换的字符串
      defaultStr - 默认字符串
      Returns:
      字符串本身或指定的默认字符串
    • emptyToDefault

      public static String emptyToDefault(CharSequence text, String defaultStr)
      如果字符串是null或者"",则返回指定默认字符串,否则返回字符串本身。
       emptyToDefault(null, "default")  = "default"
       emptyToDefault("", "default")    = "default"
       emptyToDefault("  ", "default")  = "  "
       emptyToDefault("bat", "default") = "bat"
       
      Parameters:
      text - 要转换的字符串
      defaultStr - 默认字符串
      Returns:
      字符串本身或指定的默认字符串
    • blankToDefault

      public static String blankToDefault(CharSequence text, String defaultStr)
      如果字符串是null或者""或者空白,则返回指定默认字符串,否则返回字符串本身。
       emptyToDefault(null, "default")  = "default"
       emptyToDefault("", "default")    = "default"
       emptyToDefault("  ", "default")  = "default"
       emptyToDefault("bat", "default") = "bat"
       
      Parameters:
      text - 要转换的字符串
      defaultStr - 默认字符串
      Returns:
      字符串本身或指定的默认字符串
    • isSubEquals

      public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, boolean ignoreCase)
      截取第一个字串的部分字符,与第二个字符串比较(长度一致),判断截取的子串是否相同 任意一个字符串为null返回false
      Parameters:
      str1 - 第一个字符串
      start1 - 第一个字符串开始的位置
      str2 - 第二个字符串
      ignoreCase - 是否忽略大小写
      Returns:
      子串是否相同
    • isSubEquals

      public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase)
      截取两个字符串的不同部分(长度一致),判断截取的子串是否相同 任意一个字符串为null返回false
      Parameters:
      str1 - 第一个字符串
      start1 - 第一个字符串开始的位置
      str2 - 第二个字符串
      start2 - 第二个字符串开始的位置
      length - 截取长度
      ignoreCase - 是否忽略大小写
      Returns:
      子串是否相同
    • repeat

      public static String repeat(char c, int count)
      重复某个字符
      Parameters:
      c - 被重复的字符
      count - 重复的数目,如果小于等于0则返回""
      Returns:
      重复字符字符串
    • repeat

      public static String repeat(CharSequence text, int count)
      重复某个字符串
      Parameters:
      text - 被重复的字符
      count - 重复的数目
      Returns:
      重复字符字符串
    • repeatByLength

      public static String repeatByLength(CharSequence text, int padLen)
      重复某个字符串到指定长度
      Parameters:
      text - 被重复的字符
      padLen - 指定长度
      Returns:
      重复字符字符串
    • repeatAndJoin

      public static String repeatAndJoin(CharSequence text, int count, CharSequence delimiter)
      重复某个字符串并通过分界符连接
       StringKit.repeatAndJoin("?", 5, ",")   = "?,?,?,?,?"
       StringKit.repeatAndJoin("?", 0, ",")   = ""
       StringKit.repeatAndJoin("?", 5, null)  = "?????"
       
      Parameters:
      text - 被重复的字符串
      count - 数量
      delimiter - 分界符
      Returns:
      连接后的字符串
    • reverse

      public static String reverse(String text)
      反转字符串 例如:abcd = dcba
      Parameters:
      text - 被反转的字符串
      Returns:
      反转后的字符串
    • bytes

      public static byte[] bytes(CharSequence text)
      编码字符串 使用系统默认编码
      Parameters:
      text - 字符串
      Returns:
      编码后的字节码
    • bytes

      public static byte[] bytes(CharSequence text, String charset)
      编码字符串
      Parameters:
      text - 字符串
      charset - 字符集,如果此字段为空,则解码的结果取决于平台
      Returns:
      编码后的字节码
    • bytes

      public static byte[] bytes(CharSequence text, Charset charset)
      编码字符串
      Parameters:
      text - 字符串
      charset - 字符集,如果此字段为空,则解码的结果取决于平台
      Returns:
      编码后的字节码
    • replaceIgnoreCase

      public static String replaceIgnoreCase(CharSequence text, CharSequence word, CharSequence replacement)
      替换字符串中的指定字符串,忽略大小写
      Parameters:
      text - 字符串
      word - 被查找的字符串
      replacement - 被替换的字符串
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text)
      替换字符串中的空格、回车、换行符、制表符
      Parameters:
      text - 字符串信息
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, CharSequence word, CharSequence replacement)
      替换字符串中的指定字符串
      Parameters:
      text - 字符串
      word - 被查找的字符串
      replacement - 被替换的字符串
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, CharSequence word, CharSequence replacement, boolean ignoreCase)
      替换字符串中的指定字符串
      Parameters:
      text - 字符串
      word - 被查找的字符串
      replacement - 被替换的字符串
      ignoreCase - 是否忽略大小写
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, int fromIndex, CharSequence word, CharSequence replacement, boolean ignoreCase)
      替换字符串中的指定字符串
      Parameters:
      text - 字符串
      fromIndex - 开始位置(包括)
      word - 被查找的字符串
      replacement - 被替换的字符串
      ignoreCase - 是否忽略大小写
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, String regex, Func1<Matcher,String> replaceFun)
      替换所有正则匹配的文本,并使用自定义函数决定如何替换
      Parameters:
      text - 要替换的字符串
      regex - 用于匹配的正则式
      replaceFun - 决定如何替换的函数
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, int startInclude, int endExclude, CharSequence replacedStr)
      替换指定字符串的指定区间内字符为指定字符串,字符串只重复一次 此方法使用String.codePoints()完成拆分替换
      Parameters:
      text - 字符串
      startInclude - 开始位置(包含)
      endExclude - 结束位置(不包含)
      replacedStr - 被替换的字符串
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, Pattern pattern, Func1<Matcher,String> replaceFun)
      替换所有正则匹配的文本,并使用自定义函数决定如何替换 replaceFun可以通过Matcher提取出匹配到的内容的不同部分,然后经过重新处理、组装变成新的内容放回原位。
           replace(this.content, "(\\d+)", parameters -> "-" + parameters.group(1) + "-")
           // 结果为:"ZZZaaabbbccc中文-1234-"
       
      Parameters:
      text - 要替换的字符串
      pattern - 用于匹配的正则式
      replaceFun - 决定如何替换的函数
      Returns:
      替换后的字符串
    • replace

      public static String replace(CharSequence text, int startInclude, int endExclude, char replacedChar)
      替换指定字符串的指定区间内字符为固定字符
      Parameters:
      text - 字符串
      startInclude - 开始位置(包含)
      endExclude - 结束位置(不包含)
      replacedChar - 被替换的字符
      Returns:
      替换后的字符串
    • hide

      public static String hide(CharSequence text, int startInclude, int endExclude)
      替换指定字符串的指定区间内字符为"*"
      Parameters:
      text - 字符串
      startInclude - 开始位置(包含)
      endExclude - 结束位置(不包含)
      Returns:
      替换后的字符串
    • replaceChars

      public static String replaceChars(CharSequence text, String chars, CharSequence replacedStr)
      替换字符字符数组中所有的字符为replacedStr 提供的chars为所有需要被替换的字符,例如:"\r\n",则"\r"和"\n"都会被替换,哪怕他们单独存在
      Parameters:
      text - 被检查的字符串
      chars - 需要替换的字符列表,用一个字符串表示这个字符列表
      replacedStr - 替换成的字符串
      Returns:
      新字符串
    • replaceChars

      public static String replaceChars(CharSequence text, char[] chars, CharSequence replacedStr)
      替换字符字符数组中所有的字符为replacedStr
      Parameters:
      text - 被检查的字符串
      chars - 需要替换的字符列表
      replacedStr - 替换成的字符串
      Returns:
      新字符串
    • cleanBlank

      public static String cleanBlank(CharSequence text)
      清理空白字符
      Parameters:
      text - 被清理的字符串
      Returns:
      清理后的字符串
    • wrap

      public static String wrap(CharSequence text, CharSequence prefixAndSuffix)
      包装指定字符串 当前缀和后缀一致时使用此方法
      Parameters:
      text - 被包装的字符串
      prefixAndSuffix - 前缀和后缀
      Returns:
      包装后的字符串
    • wrap

      public static String wrap(CharSequence text, CharSequence prefix, CharSequence suffix)
      包装指定字符串
      Parameters:
      text - 被包装的字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      包装后的字符串
    • wrapAll

      public static String[] wrapAll(CharSequence prefixAndSuffix, CharSequence... texts)
      包装多个字符串
      Parameters:
      prefixAndSuffix - 前缀和后缀
      texts - 多个字符串
      Returns:
      包装的字符串数组
    • wrapAll

      public static String[] wrapAll(CharSequence prefix, CharSequence suffix, CharSequence... texts)
      包装多个字符串
      Parameters:
      prefix - 前缀
      suffix - 后缀
      texts - 多个字符串
      Returns:
      包装的字符串数组
    • unWrap

      public static String unWrap(CharSequence text, String prefix, String suffix)
      去掉字符包装,如果未被包装则返回原字符串
      Parameters:
      text - 字符串
      prefix - 前置字符串
      suffix - 后置字符串
      Returns:
      去掉包装字符的字符串
    • unWrap

      public static String unWrap(CharSequence text, char prefix, char suffix)
      去掉字符包装,如果未被包装则返回原字符串
      Parameters:
      text - 字符串
      prefix - 前置字符
      suffix - 后置字符
      Returns:
      去掉包装字符的字符串
    • unWrap

      public static String unWrap(CharSequence text, char prefixAndSuffix)
      去掉字符包装,如果未被包装则返回原字符串
      Parameters:
      text - 字符串
      prefixAndSuffix - 前置和后置字符
      Returns:
      去掉包装字符的字符串
    • isWrap

      public static boolean isWrap(CharSequence text, String prefix, String suffix)
      指定字符串是否被包装
      Parameters:
      text - 字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      是否被包装
    • isWrap

      public static boolean isWrap(CharSequence text, String wrapper)
      指定字符串是否被同一字符包装(前后都有这些字符串)
      Parameters:
      text - 字符串
      wrapper - 包装字符串
      Returns:
      是否被包装
    • isWrap

      public static boolean isWrap(CharSequence text, char wrapper)
      指定字符串是否被同一字符包装(前后都有这些字符串)
      Parameters:
      text - 字符串
      wrapper - 包装字符
      Returns:
      是否被包装
    • isWrap

      public static boolean isWrap(CharSequence text, char prefixChar, char suffixChar)
      指定字符串是否被包装
      Parameters:
      text - 字符串
      prefixChar - 前缀
      suffixChar - 后缀
      Returns:
      是否被包装
    • wrapIfMissing

      public static String wrapIfMissing(CharSequence text, CharSequence prefix, CharSequence suffix)
      包装指定字符串,如果前缀或后缀已经包含对应的字符串,则不再包装
      Parameters:
      text - 被包装的字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      包装后的字符串
    • wrapAllIfMissing

      public static String[] wrapAllIfMissing(CharSequence prefixAndSuffix, CharSequence... texts)
      包装多个字符串,如果已经包装,则不再包装
      Parameters:
      prefixAndSuffix - 前缀和后缀
      texts - 多个字符串
      Returns:
      包装的字符串数组
    • wrapAllIfMissing

      public static String[] wrapAllIfMissing(CharSequence prefix, CharSequence suffix, CharSequence... texts)
      包装多个字符串,如果已经包装,则不再包装
      Parameters:
      prefix - 前缀
      suffix - 后缀
      texts - 多个字符串
      Returns:
      包装的字符串数组
    • startWith

      public static boolean startWith(CharSequence text, char c)
      字符串是否以给定字符开始
      Parameters:
      text - 字符串
      c - 字符
      Returns:
      是否开始
    • startWith

      public static boolean startWith(CharSequence text, CharSequence prefix, boolean ignoreCase)
      是否以指定字符串开头 如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
      Parameters:
      text - 被监测字符串
      prefix - 开头字符串
      ignoreCase - 是否忽略大小写
      Returns:
      是否以指定字符串开头
    • startWith

      public static boolean startWith(CharSequence text, CharSequence prefix, boolean ignoreCase, boolean ignoreEquals)
      是否以指定字符串开头 如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
      Parameters:
      text - 被监测字符串
      prefix - 开头字符串
      ignoreCase - 是否忽略大小写
      ignoreEquals - 是否忽略字符串相等的情况
      Returns:
      是否以指定字符串开头
    • startWith

      public static boolean startWith(CharSequence text, CharSequence prefix)
      是否以指定字符串开头
      Parameters:
      text - 被监测字符串
      prefix - 开头字符串
      Returns:
      是否以指定字符串开头
    • startWithIgnoreEquals

      public static boolean startWithIgnoreEquals(CharSequence text, CharSequence prefix)
      是否以指定字符串开头,忽略相等字符串的情况
      Parameters:
      text - 被监测字符串
      prefix - 开头字符串
      Returns:
      是否以指定字符串开头并且两个字符串不相等
    • startWithAny

      public static boolean startWithAny(CharSequence text, CharSequence... prefixes)
      给定字符串是否以任何一个字符串开始 给定字符串和数组为空都返回false
      Parameters:
      text - 给定字符串
      prefixes - 需要检测的开始字符串
      Returns:
      给定字符串是否以任何一个字符串开始
    • startWithAnyIgnoreCase

      public static boolean startWithAnyIgnoreCase(CharSequence text, CharSequence... suffixes)
      给定字符串是否以任何一个字符串结尾(忽略大小写) 给定字符串和数组为空都返回false
      Parameters:
      text - 给定字符串
      suffixes - 需要检测的结尾字符串
      Returns:
      给定字符串是否以任何一个字符串结尾
    • startWithIgnoreCase

      public static boolean startWithIgnoreCase(CharSequence text, CharSequence prefix)
      是否以指定字符串开头,忽略大小写
      Parameters:
      text - 被监测字符串
      prefix - 开头字符串
      Returns:
      是否以指定字符串开头
    • endWith

      public static boolean endWith(CharSequence text, char c)
      字符串是否以给定字符结尾
      Parameters:
      text - 字符串
      c - 字符
      Returns:
      是否结尾
    • endWith

      public static boolean endWith(CharSequence text, CharSequence suffix, boolean ignoreCase)
      是否以指定字符串结尾 如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
      Parameters:
      text - 被监测字符串
      suffix - 结尾字符串
      ignoreCase - 是否忽略大小写
      Returns:
      是否以指定字符串结尾
    • endWith

      public static boolean endWith(CharSequence text, CharSequence suffix, boolean ignoreCase, boolean ignoreEquals)
      是否以指定字符串结尾 如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
      Parameters:
      text - 被监测字符串
      suffix - 结尾字符串
      ignoreCase - 是否忽略大小写
      ignoreEquals - 是否忽略字符串相等的情况
      Returns:
      是否以指定字符串结尾
    • endWith

      public static boolean endWith(CharSequence text, CharSequence suffix)
      是否以指定字符串结尾
      Parameters:
      text - 被监测字符串
      suffix - 结尾字符串
      Returns:
      是否以指定字符串结尾
    • endWithAny

      public static boolean endWithAny(CharSequence text, CharSequence... suffixes)
      给定字符串是否以任何一个字符串结尾 给定字符串和数组为空都返回false
      Parameters:
      text - 给定字符串
      suffixes - 需要检测的结尾字符串
      Returns:
      给定字符串是否以任何一个字符串结尾
    • endWithAnyIgnoreCase

      public static boolean endWithAnyIgnoreCase(CharSequence text, CharSequence... suffixes)
      给定字符串是否以任何一个字符串结尾(忽略大小写) 给定字符串和数组为空都返回false
      Parameters:
      text - 给定字符串
      suffixes - 需要检测的结尾字符串
      Returns:
      给定字符串是否以任何一个字符串结尾
    • endWithIgnoreCase

      public static boolean endWithIgnoreCase(CharSequence text, CharSequence suffix)
      是否以指定字符串结尾,忽略大小写
      Parameters:
      text - 被监测字符串
      suffix - 结尾字符串
      Returns:
      是否以指定字符串结尾
    • strip

      public static String strip(CharSequence text, CharSequence prefixOrSuffix)
      去除两边的指定字符串
      Parameters:
      text - 被处理的字符串
      prefixOrSuffix - 前缀或后缀
      Returns:
      处理后的字符串
    • strip

      public static String strip(CharSequence text, CharSequence prefix, CharSequence suffix)
      去除两边的指定字符串
      Parameters:
      text - 被处理的字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      处理后的字符串
    • stripIgnoreCase

      public static String stripIgnoreCase(CharSequence text, CharSequence prefixOrSuffix)
      去除两边的指定字符串,忽略大小写
      Parameters:
      text - 被处理的字符串
      prefixOrSuffix - 前缀或后缀
      Returns:
      处理后的字符串
    • stripIgnoreCase

      public static String stripIgnoreCase(CharSequence text, CharSequence prefix, CharSequence suffix)
      去除两边的指定字符串,忽略大小写
      Parameters:
      text - 被处理的字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      处理后的字符串
    • addPrefixIfNot

      public static String addPrefixIfNot(CharSequence text, CharSequence prefix)
      如果给定字符串不是以prefix开头的,在开头补充 prefix
      Parameters:
      text - 字符串
      prefix - 前缀
      Returns:
      补充后的字符串
    • addSuffixIfNot

      public static String addSuffixIfNot(CharSequence text, CharSequence suffix)
      如果给定字符串不是以suffix结尾的,在尾部补充 suffix
      Parameters:
      text - 字符串
      suffix - 后缀
      Returns:
      补充后的字符串
    • contains

      public static boolean contains(CharSequence text, char searchChar)
      指定字符是否在字符串中出现过
      Parameters:
      text - 字符串
      searchChar - 被查找的字符
      Returns:
      是否包含
    • contains

      public static boolean contains(CharSequence text, CharSequence word)
      指定字符串是否在字符串中出现过
      Parameters:
      text - 字符串
      word - 被查找的字符串
      Returns:
      是否包含
    • containsAny

      public static boolean containsAny(CharSequence text, CharSequence... testStrs)
      查找指定字符串是否包含指定字符串列表中的任意一个字符串
      Parameters:
      text - 指定字符串
      testStrs - 需要检查的字符串数组
      Returns:
      是否包含任意一个字符串
    • containsAny

      public static boolean containsAny(CharSequence text, char... testChars)
      查找指定字符串是否包含指定字符列表中的任意一个字符
      Parameters:
      text - 指定字符串
      testChars - 需要检查的字符数组
      Returns:
      是否包含任意一个字符
    • containsOnly

      public static boolean containsOnly(CharSequence text, char... testChars)
      检查指定字符串中是否只包含给定的字符
      Parameters:
      text - 字符串
      testChars - 检查的字符
      Returns:
      字符串含有非检查的字符, 返回false
    • containsBlank

      public static boolean containsBlank(CharSequence text)
      给定字符串是否包含空白符(空白符包括空格、制表符、全角空格和不间断空格) 如果给定字符串为null或者"",则返回false
      Parameters:
      text - 字符串
      Returns:
      是否包含空白符
    • getContainsAny

      public static String getContainsAny(CharSequence text, CharSequence... testStrs)
      查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串
      Parameters:
      text - 指定字符串
      testStrs - 需要检查的字符串数组
      Returns:
      被包含的第一个字符串
    • containsIgnoreCase

      public static boolean containsIgnoreCase(CharSequence text, CharSequence testStr)
      是否包含特定字符,忽略大小写,如果给定两个参数都为null,返回true
      Parameters:
      text - 被检测字符串
      testStr - 被测试是否包含的字符串
      Returns:
      是否包含
    • containsAnyIgnoreCase

      public static boolean containsAnyIgnoreCase(CharSequence text, CharSequence... testStrs)
      查找指定字符串是否包含指定字符串列表中的任意一个字符串 忽略大小写
      Parameters:
      text - 指定字符串
      testStrs - 需要检查的字符串数组
      Returns:
      是否包含任意一个字符串
    • getContainsStrIgnoreCase

      public static String getContainsStrIgnoreCase(CharSequence text, CharSequence... testStrs)
      查找指定字符串是否包含指定字符串列表中的任意一个字符串,如果包含返回找到的第一个字符串 忽略大小写
      Parameters:
      text - 指定字符串
      testStrs - 需要检查的字符串数组
      Returns:
      被包含的第一个字符串
    • isSurround

      public static boolean isSurround(CharSequence text, CharSequence prefix, CharSequence suffix)
      给定字符串是否被字符包围
      Parameters:
      text - 字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      是否包围, 空串不包围
    • isSurround

      public static boolean isSurround(CharSequence text, char prefix, char suffix)
      给定字符串是否被字符包围
      Parameters:
      text - 字符串
      prefix - 前缀
      suffix - 后缀
      Returns:
      是否包围, 空串不包围
    • isUpperCase

      public static boolean isUpperCase(CharSequence text)
      给定字符串中的字母是否全部为大写,判断依据如下:
       1. 大写字母包括A-Z
       2. 其它非字母的Unicode符都算作大写
       
      Parameters:
      text - 被检查的字符串
      Returns:
      是否全部为大写
    • isLowerCase

      public static boolean isLowerCase(CharSequence text)
      给定字符串中的字母是否全部为小写,判断依据如下:
       1. 小写字母包括a-z
       2. 其它非字母的Unicode符都算作小写
       
      Parameters:
      text - 被检查的字符串
      Returns:
      是否全部为小写
    • byteLength

      public static int byteLength(CharSequence cs, Charset charset)
      给定字符串转为bytes后的byte数(byte长度)
      Parameters:
      cs - 字符串
      charset - 编码
      Returns:
      byte长度
    • cut

      public static String[] cut(CharSequence text, int partLength)
      将字符串切分为N等份
      Parameters:
      text - 字符串
      partLength - 每等份的长度
      Returns:
      切分后的数组
    • brief

      public static String brief(CharSequence text, int maxLength)
      将给定字符串,变成 "xxx...xxx" 形式的字符串
      • abcdef 5 -》 a...f
      • abcdef 4 -》 a..f
      • abcdef 3 -》 a.f
      • abcdef 2 -》 a.
      • abcdef 1 -》 a
      Parameters:
      text - 字符串
      maxLength - 最大长度
      Returns:
      截取后的字符串
    • appendIfMissing

      public static String appendIfMissing(String text, CharSequence suffix, CharSequence... suffixes)
      如果字符串还没有以任何后缀结尾,则将后缀追加到字符串的末尾.
       StringKit.appendIfMissing(null, null) = null
       StringKit.appendIfMissing("abc", null) = "abc"
       StringKit.appendIfMissing("", "xyz") = "xyz"
       StringKit.appendIfMissing("abc", "xyz") = "abcxyz"
       StringKit.appendIfMissing("abcxyz", "xyz") = "abcxyz"
       StringKit.appendIfMissing("abcXYZ", "xyz") = "abcXYZxyz"
       

      With additional suffixes,

       StringKit.appendIfMissing(null, null, null) = null
       StringKit.appendIfMissing("abc", null, null) = "abc"
       StringKit.appendIfMissing("", "xyz", null) = "xyz"
       StringKit.appendIfMissing("abc", "xyz", new CharSequence[]{null}) = "abcxyz"
       StringKit.appendIfMissing("abc", "xyz", "") = "abc"
       StringKit.appendIfMissing("abc", "xyz", "mno") = "abcxyz"
       StringKit.appendIfMissing("abcxyz", "xyz", "mno") = "abcxyz"
       StringKit.appendIfMissing("abcmno", "xyz", "mno") = "abcmno"
       StringKit.appendIfMissing("abcXYZ", "xyz", "mno") = "abcXYZxyz"
       StringKit.appendIfMissing("abcMNO", "xyz", "mno") = "abcMNOxyz"
       
      Parameters:
      text - 字符串.
      suffix - 附加到字符串末尾的后缀.
      suffixes - 有效终止符的附加后缀(可选).
      Returns:
      如果添加了后缀,则为新字符串,否则为相同的字符串.
    • appendIfMissingIgnoreCase

      public static String appendIfMissingIgnoreCase(String text, CharSequence suffix, CharSequence... suffixes)
      如果字符串还没有结束,则使用任何后缀将后缀追加到字符串的末尾,不区分大小写.
       StringKit.appendIfMissingIgnoreCase(null, null) = null
       StringKit.appendIfMissingIgnoreCase("abc", null) = "abc"
       StringKit.appendIfMissingIgnoreCase("", "xyz") = "xyz"
       StringKit.appendIfMissingIgnoreCase("abc", "xyz") = "abcxyz"
       StringKit.appendIfMissingIgnoreCase("abcxyz", "xyz") = "abcxyz"
       StringKit.appendIfMissingIgnoreCase("abcXYZ", "xyz") = "abcXYZ"
       

      With additional suffixes,

       StringKit.appendIfMissingIgnoreCase(null, null, null) = null
       StringKit.appendIfMissingIgnoreCase("abc", null, null) = "abc"
       StringKit.appendIfMissingIgnoreCase("", "xyz", null) = "xyz"
       StringKit.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "abcxyz"
       StringKit.appendIfMissingIgnoreCase("abc", "xyz", "") = "abc"
       StringKit.appendIfMissingIgnoreCase("abc", "xyz", "mno") = "axyz"
       StringKit.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno") = "abcxyz"
       StringKit.appendIfMissingIgnoreCase("abcmno", "xyz", "mno") = "abcmno"
       StringKit.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno") = "abcXYZ"
       StringKit.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno") = "abcMNO"
       
      Parameters:
      text - 字符串.
      suffix - 附加到字符串末尾的后缀.
      suffixes - 有效终止符的附加后缀(可选).
      Returns:
      如果添加了后缀,则为新字符串,否则为相同的字符串.
    • prependIfMissing

      public static String prependIfMissing(String text, CharSequence prefix, CharSequence... prefixes)
      如果字符串还没有以任何前缀开始,则将前缀添加到字符串的开头.
       StringKit.prependIfMissing(null, null) = null
       StringKit.prependIfMissing("abc", null) = "abc"
       StringKit.prependIfMissing("", "xyz") = "xyz"
       StringKit.prependIfMissing("abc", "xyz") = "xyzabc"
       StringKit.prependIfMissing("xyzabc", "xyz") = "xyzabc"
       StringKit.prependIfMissing("XYZabc", "xyz") = "xyzXYZabc"
       

      With additional prefixes,

       StringKit.prependIfMissing(null, null, null) = null
       StringKit.prependIfMissing("abc", null, null) = "abc"
       StringKit.prependIfMissing("", "xyz", null) = "xyz"
       StringKit.prependIfMissing("abc", "xyz", new CharSequence[]{null}) = "xyzabc"
       StringKit.prependIfMissing("abc", "xyz", "") = "abc"
       StringKit.prependIfMissing("abc", "xyz", "mno") = "xyzabc"
       StringKit.prependIfMissing("xyzabc", "xyz", "mno") = "xyzabc"
       StringKit.prependIfMissing("mnoabc", "xyz", "mno") = "mnoabc"
       StringKit.prependIfMissing("XYZabc", "xyz", "mno") = "xyzXYZabc"
       StringKit.prependIfMissing("MNOabc", "xyz", "mno") = "xyzMNOabc"
       
      Parameters:
      text - T字符串.
      prefix - 在字符串开始前的前缀.
      prefixes - 有效的附加前缀(可选).
      Returns:
      如果前缀是前缀,则为新字符串,否则为相同的字符串.
    • prependIfMissingIgnoreCase

      public static String prependIfMissingIgnoreCase(String text, CharSequence prefix, CharSequence... prefixes)
      如果字符串尚未开始,则将前缀添加到字符串的开头,不区分大小写,并使用任何前缀.
       StringKit.prependIfMissingIgnoreCase(null, null) = null
       StringKit.prependIfMissingIgnoreCase("abc", null) = "abc"
       StringKit.prependIfMissingIgnoreCase("", "xyz") = "xyz"
       StringKit.prependIfMissingIgnoreCase("abc", "xyz") = "xyzabc"
       StringKit.prependIfMissingIgnoreCase("xyzabc", "xyz") = "xyzabc"
       StringKit.prependIfMissingIgnoreCase("XYZabc", "xyz") = "XYZabc"
       

      With additional prefixes,

       StringKit.prependIfMissingIgnoreCase(null, null, null) = null
       StringKit.prependIfMissingIgnoreCase("abc", null, null) = "abc"
       StringKit.prependIfMissingIgnoreCase("", "xyz", null) = "xyz"
       StringKit.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "xyzabc"
       StringKit.prependIfMissingIgnoreCase("abc", "xyz", "") = "abc"
       StringKit.prependIfMissingIgnoreCase("abc", "xyz", "mno") = "xyzabc"
       StringKit.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno") = "xyzabc"
       StringKit.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno") = "mnoabc"
       StringKit.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno") = "XYZabc"
       StringKit.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno") = "MNOabc"
       
      Parameters:
      text - T字符串.
      prefix - 在字符串开始前的前缀.
      prefixes - 有效的附加前缀(可选).
      Returns:
      如果前缀是前缀,则为新字符串,否则为相同的字符串.
    • maxLength

      public static String maxLength(CharSequence string, int length)
      限制字符串长度,如果超过指定长度,截取指定长度并在末尾加"..."
      Parameters:
      string - 字符串
      length - 最大长度
      Returns:
      切割后的剩余的前半部分字符串+"..."
    • center

      public static String center(CharSequence text, int size)
      居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
       StringKit.center(null, *)   = null
       StringKit.center("", 4)     = "    "
       StringKit.center("ab", -1)  = "ab"
       StringKit.center("ab", 4)   = " ab "
       StringKit.center("abcd", 2) = "abcd"
       StringKit.center("a", 4)    = " a  "
       
      Parameters:
      text - 字符串
      size - 指定长度
      Returns:
      补充后的字符串
    • center

      public static String center(CharSequence text, int size, char padChar)
      居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
       StringKit.center(null, *, *)     = null
       StringKit.center("", 4, ' ')     = "    "
       StringKit.center("ab", -1, ' ')  = "ab"
       StringKit.center("ab", 4, ' ')   = " ab "
       StringKit.center("abcd", 2, ' ') = "abcd"
       StringKit.center("a", 4, ' ')    = " a  "
       StringKit.center("a", 4, 'y')   = "yayy"
       StringKit.center("abc", 7, ' ')   = "  abc  "
       
      Parameters:
      text - 字符串
      size - 指定长度
      padChar - 两边补充的字符
      Returns:
      补充后的字符串
    • center

      public static String center(CharSequence text, int size, CharSequence padStr)
      居中字符串,两边补充指定字符串,如果指定长度小于字符串,则返回原字符串
       StringKit.center(null, *, *)     = null
       StringKit.center("", 4, " ")     = "    "
       StringKit.center("ab", -1, " ")  = "ab"
       StringKit.center("ab", 4, " ")   = " ab "
       StringKit.center("abcd", 2, " ") = "abcd"
       StringKit.center("a", 4, " ")    = " a  "
       StringKit.center("a", 4, "yz")   = "yayz"
       StringKit.center("abc", 7, null) = "  abc  "
       StringKit.center("abc", 7, "")   = "  abc  "
       
      Parameters:
      text - 字符串
      size - 指定长度
      padStr - 两边补充的字符串
      Returns:
      补充后的字符串
    • padPre

      public static String padPre(CharSequence text, int minLength, CharSequence padStr)
      补充字符串以满足最小长度
       StringKit.padPre(null, *, *);//null
       StringKit.padPre("1", 3, "ABC");//"AB1"
       StringKit.padPre("123", 2, "ABC");//"12"
       
      Parameters:
      text - 字符串
      minLength - 最小长度
      padStr - 补充的字符
      Returns:
      补充后的字符串
    • padPre

      public static String padPre(CharSequence text, int minLength, char padChar)
      补充字符串以满足最小长度
       StringKit.padPre(null, *, *);//null
       StringKit.padPre("1", 3, '0');//"001"
       StringKit.padPre("123", 2, '0');//"12"
       
      Parameters:
      text - 字符串
      minLength - 最小长度
      padChar - 补充的字符
      Returns:
      补充后的字符串
    • padAfter

      public static String padAfter(CharSequence text, int minLength, char padChar)
      补充字符串以满足最小长度
       StringKit.padAfter(null, *, *);//null
       StringKit.padAfter("1", 3, '0');//"100"
       StringKit.padAfter("123", 2, '0');//"23"
       
      Parameters:
      text - 字符串,如果为null,直接返回null
      minLength - 最小长度
      padChar - 补充的字符
      Returns:
      补充后的字符串
    • padAfter

      public static String padAfter(CharSequence text, int minLength, CharSequence padStr)
      补充字符串以满足最小长度
       StringKit.padAfter(null, *, *);//null
       StringKit.padAfter("1", 3, "ABC");//"1AB"
       StringKit.padAfter("123", 2, "ABC");//"23"
       
      Parameters:
      text - 字符串,如果为null,直接返回null
      minLength - 最小长度
      padStr - 补充的字符
      Returns:
      补充后的字符串
    • equalsCharAt

      public static boolean equalsCharAt(CharSequence text, int position, char c)
      字符串指定位置的字符是否与给定字符相同 如果字符串为null,返回false 如果给定的位置大于字符串长度,返回false 如果给定的位置小于0,返回false
      Parameters:
      text - 字符串
      position - 位置
      c - 需要对比的字符
      Returns:
      字符串指定位置的字符是否与给定字符相同
    • filter

      public static String filter(CharSequence text, Filter<Character> filter)
      过滤字符串
      Parameters:
      text - 字符串
      filter - 过滤器
      Returns:
      过滤后的字符串
    • builder

      public static StringBuilder builder(CharSequence... text)
      创建StringBuilder对象
      Parameters:
      text - 初始字符串列表
      Returns:
      StringBuilder对象
    • length

      public static int length(CharSequence cs)
      获取字符串的长度,如果为null返回0
      Parameters:
      cs - a 字符串
      Returns:
      字符串的长度, 如果为null返回0
    • ordinalIndexOf

      public static int ordinalIndexOf(CharSequence text, CharSequence word, int ordinal)
      返回字符串 word 在字符串 text 中第 ordinal 次出现的位置 如果 text=null 或 word=null 或 ordinal小于等于0 则返回-1
       StringKit.ordinalIndexOf(null, *, *)          = -1
       StringKit.ordinalIndexOf(*, null, *)          = -1
       StringKit.ordinalIndexOf("", "", *)           = 0
       StringKit.ordinalIndexOf("aabaabaa", "a", 1)  = 0
       StringKit.ordinalIndexOf("aabaabaa", "a", 2)  = 1
       StringKit.ordinalIndexOf("aabaabaa", "b", 1)  = 2
       StringKit.ordinalIndexOf("aabaabaa", "b", 2)  = 5
       StringKit.ordinalIndexOf("aabaabaa", "ab", 1) = 1
       StringKit.ordinalIndexOf("aabaabaa", "ab", 2) = 4
       StringKit.ordinalIndexOf("aabaabaa", "", 1)   = 0
       StringKit.ordinalIndexOf("aabaabaa", "", 2)   = 0
       
      Parameters:
      text - 被检查的字符串,可以为null
      word - 被查找的字符串,可以为null
      ordinal - 第几次出现的位置
      Returns:
      查找到的位置
    • toString

      public static String toString(CharSequence cs)
      CharSequence 转为字符串,null安全
      Parameters:
      cs - CharSequence
      Returns:
      字符串
    • toString

      public static String toString(char c)
      字符转为字符串 如果为ASCII字符,使用缓存
      Parameters:
      c - 字符
      Returns:
      字符串
    • endsWithAny

      public static boolean endsWithAny(CharSequence text, CharSequence... word)
      检查CharSequence是否以提供的大小写敏感的后缀结尾.
       StringKit.endsWithAny(null, null)      = false
       StringKit.endsWithAny(null, new String[] {"abc"})  = false
       StringKit.endsWithAny("abcxyz", null)     = false
       StringKit.endsWithAny("abcxyz", new String[] {""}) = true
       StringKit.endsWithAny("abcxyz", new String[] {"xyz"}) = true
       StringKit.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
       StringKit.endsWithAny("abcXYZ", "def", "XYZ") = true
       StringKit.endsWithAny("abcXYZ", "def", "xyz") = false
       
      Parameters:
      text - 要检查的CharSequence可能为空
      word - 要查找的区分大小写的字符序列可以是空的,也可以包含null
      Returns:
      {如果输入sequencenull, 并且没有提供searchstring, 或者输入sequence以提供的区分大小写的searchstring结尾.
    • firstNonNull

      public static <T extends CharSequence> T firstNonNull(T... texts)
      返回第一个非null元素
      Type Parameters:
      T - 元素类型
      Parameters:
      texts - 多个元素
      Returns:
      第一个非空元素,如果给定的数组为空或者都为空,返回null
    • firstNonEmpty

      public static <T extends CharSequence> T firstNonEmpty(T... texts)
      返回第一个非empty元素
      Type Parameters:
      T - 元素类型
      Parameters:
      texts - 多个元素
      Returns:
      第一个非空元素,如果给定的数组为空或者都为空,返回null
      See Also:
    • firstNonBlank

      public static <T extends CharSequence> T firstNonBlank(T... texts)
      返回第一个非blank 元素
      Type Parameters:
      T - 元素类型
      Parameters:
      texts - 多个元素
      Returns:
      第一个非空元素,如果给定的数组为空或者都为空,返回null
      See Also: