|
67.public static String deleteWhitespace(String str)
删除字符串中的所有空白符(whitespace),空白符是这样定义的{@link Character#isWhitespace(char)}。
举例(*表示任意):
StringUtils.deleteWhitespace(null) = null
StringUtils.deleteWhitespace("") = ""
StringUtils.deleteWhitespace("asd")) = "asd",
StringUtils.deleteWhitespace("as df")) = "asdf"
StringUtils.deleteWhitespace("as\n\r\f\tdf")) = "asdf"
StringUtils.deleteWhitespace("as\bdf")) = "as\bdf"
StringUtils.deleteWhitespace(" as df ")) = "asdf"
68.public static String removeStart(String str, String remove)
如果字符串str是以字符串remove开始,则去掉这个开始,然后返回,否则返回原来的串。
举例(*表示任意):
StringUtils.removeStart(null, *) = null
StringUtils.removeStart("", *) = ""
StringUtils.removeStart(*, null) = *
StringUtils.removeStart("asdf","")) = "asdf"
StringUtils.removeStart("asdf","as")) = "df"
StringUtils.removeStart("asdf","df")) = "asdf"
StringUtils.removeStart("asdf","gh")) = "asdf"
69.public static String removeEnd(String str, String remove)
如果字符串str是以字符串remove结尾,则去掉这个结尾,然后返回,否则返回原来的串。
这里不再举例。
70.public static String remove(String str, String remove)
去掉字符串str中所有包含remove的部分,然后返回。
这里不再举例。
71.public static String remove(String str, char remove)
去掉字符串str中所有包含remove的部分,然后返回。
这里不再举例。
72.public static String replaceOnce(String text, String repl, String with)
在字符串text中用with代替repl,仅一次。
这里不再举例。
73.public static String replace(String text, String repl, String with)
在字符串text中用with代替repl,替换所有。
这里不再举例。
74.public static String replace(String text, String repl, String with, int max)
在字符串text中用with代替repl,max为最大替换次数。
如果max小于0,则替换所有。
这里不再举例。
75. public static String replaceChars(String str, char searchChar, char replaceChar)
在字符串str中用字符replaceChar代替所有字符searchChar,
如果字符串为null或"",则返回它本身。
这里不再举例。
76.public static String replaceChars(String str, String searchChars, String replaceChars)
用replaceChars代替str中的searchChars。
replaceChars的长度应该和searchChars的长度相等,
如果replaceChars的长度大于searchChars的长度,超过长度的字符将被忽略,
如果replaceChars的长度小于searchChars的长度,超过长度的字符将被删除。
举例(*表示任意):
StringUtils.replaceChars(null, *, *) = null
StringUtils.replaceChars("", *, *) = ""
StringUtils.replaceChars("asdf", null, *) = "asdf"
StringUtils.replaceChars("asdf", "", *) = "asdf"
StringUtils.replaceChars("asdf","s",null)) = "adf"
StringUtils.replaceChars("asdf","s","")) = "adf"
StringUtils.replaceChars("asdsfsg","s","y")) = "aydyfyg"
StringUtils.replaceChars("asdf","sd","yy")) = "ayyf"
StringUtils.replaceChars("asdf","sd","yyy")) = "ayyf"
StringUtils.replaceChars("asssdf","s","yyy")) = "ayyydf"
StringUtils.replaceChars("asdf","sd","y")) = "ayf"
StringUtils.replaceChars("assssddddf","sd","y"))= "ayyyyf"
77.public static String overlay(String str, String overlay, int start, int end)
用字符串overlay覆盖字符串str从start到end之间的串。
如果str为null,则返回null
如果start或end小于0,则设为0
如果start大于end,则两者交换
如果start或end大于str的长度,则认为等于str的长度
举例(*表示任意):
StringUtils.overlay(null, *, *, *) = null
StringUtils.overlay("","as",0,0)) = "as"
StringUtils.overlay("asdfgh","qq",2,5)) = "asqqh"
StringUtils.overlay("asdfgh","qq",5,2)) = "asqqh"
StringUtils.overlay("asdfgh","qq",-1,3)) = "qqfgh"
StringUtils.overlay("asdfgh","qq",-1,-3)) = "qqasdfgh"
StringUtils.overlay("asdfgh","qq",7,10)) = "asdfghqq"
StringUtils.overlay("asdfgh","qq",0,8)) = "qq"
StringUtils.overlay("asdfgh","qq",2,8)) = "asqq"
StringUtils.overlay("asdfgh",null,2,5)) = "ash"
StringUtils.overlay("asdfgh","",2,5)) = "ash"
78.public static String chop(String str)
去掉字符串str的最后一个字符。
如果字符串以"\r\n"结尾,则去掉它们。
这里不再举例。
79.public static String repeat(String str, int repeat)
重复字符串repeat次,组合成一个新串返回。
如果字符串str为null或"",则返回它本身
如果repeat小于0,则返回""
举例(*表示任意):
StringUtils.repeat(null, *) = null
StringUtils.repeat("", *) = ""
StringUtils.repeat("a", 3) = "aaa"
StringUtils.repeat("ab", 2) = "abab"
StringUtils.repeat("a", -2) = ""
80.public static String rightPad(String str, int size)
如果str为null,则返回null
如果字符串长度小于size,则在右边补空格使其长度等于size,然后返回
如果字符串长度大于等于size,则返回它本身
这里不再举例。
81.public static String rightPad(String str, int size, char padChar)
和80类似,只是补的字符为padChar。
这里不再举例。
82.public static String rightPad(String str, int size, String padStr)
和80类似,只是补的是字符串padStr。
举例(*表示任意):
StringUtils.rightPad(null, *, *) = null
StringUtils.rightPad("",0,"")) = ""
StringUtils.rightPad("",3,"")) = " "
StringUtils.rightPad("",3,"a")) = "aaa"
StringUtils.rightPad("",2,"as")) = "as"
StringUtils.rightPad("as",-1,"df")) = "as"
StringUtils.rightPad("as",0,"df")) = "as"
StringUtils.rightPad("as",3,"df")) = "asd"
StringUtils.rightPad("as",8,"df")) = "asdfdfdf"
StringUtils.rightPad("as",5,null)) = "as "
StringUtils.rightPad("as",5,"")) = "as "
83.public static String leftPad(String str, int size)
和80类似,只是补左边。
这里不再举例。
84.public static String leftPad(String str, int size, char padChar)
和81类似。
这里不再举例。
85.public static String leftPad(String str, int size, String padStr)
和82类似。
这里不再举例。
86.public static String center(String str, int size)
产生一个字符串返回,该字符串长度等于size,str位于新串的中心,其他位置补空格。
如果str为null,则返回null
如果size小于str的长度,则返回str本身
举例(*表示任意):
StringUtils.center(null, *) = null
StringUtils.center("",1)) = " "
StringUtils.center("",2)) = " "
StringUtils.center("as",-1)) = "as"
StringUtils.center("as",2)) = "as"
StringUtils.center("as",3)) = "as "
StringUtils.center("as",4)) = " as "
StringUtils.center("as",10)) = " as "
87.public static String center(String str, int size, char padChar)
和86类似,只是其他位置补padChar。
这里不再举例。
88.public static String center(String str, int size, String padStr)
和86类似,只是其他位置补padStr。
这里不再举例。
89.public static String swapCase(String str)
把字符串中的字符大写转换为小写,小写转换为大写。
举例:
StringUtils.swapCase(null) = null
StringUtils.swapCase("") = ""
StringUtils.swapCase("Hello Boys")) = "hELLO bOYS"
StringUtils.swapCase("I am 11")) = "i AM 11"
90.public static int countMatches(String str, String sub)
计算字符串sub在字符串str中出现的次数。
如果str为null或"",则返回0
举例(*表示任意):
StringUtils.countMatches(null, *) = 0
StringUtils.countMatches("", *) = 0
StringUtils.countMatches("asdf","as")) = 1
StringUtils.countMatches("asdfas","as")) = 2
StringUtils.countMatches("dfgh","as")) = 0
StringUtils.countMatches("as","")) = 0
StringUtils.countMatches("as",null)) = 0
剩下的一些方法用的比较少或者比较简单,这里就不再介绍。
本系列的学习笔记已经完成了,如果大家看后有一些意见或者建议或者勘误希望和我联系,多谢! |
|