Apache Commons--StringUtils字符串操作


需要包:commons-lang.jar

StringUtils是字符串工具類,主要方法如下:

  1、public static boolean isEmpty(CharSequence cs):判斷字符串是否為“”或者null,    

    StringUtils.isEmpty(null) = true
    StringUtils.isEmpty("") = true
    StringUtils.isEmpty(" ") = false
    StringUtils.isEmpty("bob") = false
    StringUtils.isEmpty(" bob ") = false

  2、public static boolean isNotEmpty(CharSequence cs):判斷字符串是否不為“”或者不為null

    StringUtils.isNotEmpty(null) = false
    StringUtils.isNotEmpty("") = false
    StringUtils.isNotEmpty(" ") = true
    StringUtils.isNotEmpty("bob") = true
    StringUtils.isNotEmpty(" bob ") = true

  3、public static boolean isAnyEmpty(CharSequence... css):任意一個參數為空的話,返回true,如果這些參數都不為空的話返回false 

    StringUtils.isAnyEmpty(null) = true
    StringUtils.isAnyEmpty(null, "foo") = true
    StringUtils.isAnyEmpty("", "bar") = true
    StringUtils.isAnyEmpty("bob", "") = true
    StringUtils.isAnyEmpty(" bob ", null) = true
    StringUtils.isAnyEmpty(" ", "bar") = false
    StringUtils.isAnyEmpty("foo", "bar") = false

  4、public static boolean isNoneEmpty(CharSequence... css):任意一個參數是空,返回false,所有參數都不為空,返回true   

    StringUtils.isNoneEmpty(null) = false
    StringUtils.isNoneEmpty(null, "foo") = false
    StringUtils.isNoneEmpty("", "bar") = false
    StringUtils.isNoneEmpty("bob", "") = false
    StringUtils.isNoneEmpty(" bob ", null) = false
    StringUtils.isNoneEmpty(" ", "bar") = true
    StringUtils.isNoneEmpty("foo", "bar") = true

  5、public static boolean isBlank(CharSequence cs):判斷字符對象是不是空字符串   

    StringUtils.isBlank(null) = true
    StringUtils.isBlank("") = true
    StringUtils.isBlank(" ") = true
    StringUtils.isBlank("bob") = false
    StringUtils.isBlank(" bob ") = false

  6、public static boolean isNotBlank(CharSequence cs):判斷字符對象是不是不為空字符串

  7、public static boolean isAnyBlank(CharSequence... css):判斷字符串是不是空字符串,都是空字符串就返回true,否則返回false

  8、public static boolean isNoneBlank(CharSequence... css):判斷字符串是不是不是空字符串,全部不是空字符串就返回true,否則返回false 

  9、public static String trim(String str):去除字符串首尾的空格

  10、public static boolean equals(CharSequence cs1, CharSequence cs2):判斷字符串是否相等

  11、public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2):字符串比較,忽略大小寫

  12、public static int indexOf(CharSequence seq, int searchChar):返回字符串首次出現的位置索引

  13、public static int ordinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal):判斷字符串在另一個字符串第幾次出現的位置索引

  14、public static int lastIndexOf(CharSequence seq,int searchChar):字符在字符串中最后一次出現的位置索引

  15、public static int lastOrdinalIndexOf(CharSequence str,CharSequence searchStr, int ordinal):判斷字符在字符串倒數第幾次出現的位置索引

  16、public static boolean contains(CharSequence seq, int searchChar):判斷是字符是否在另一個字符串中

  17、public static String substring(String str,int start):字符串截取

  18、public static String left(String str,int len):字符串左邊的多少個字符

    public static String right(String str, int len):字符串右邊的多少個字符

    

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM