StringUtils工具类的使用

八、 Replacing(字符串替换)
19、
Replaces all occurances of a String within another String.


A null reference passed to this method is a no-op.


以指定字符串替换原来字符串的的指定字符串 StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("aba", null, null) = "aba" StringUtils.replace("aba", null, null) = "aba" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "aba" StringUtils.replace("aba", "a", "z") = "zbz"

@param text text to search and replace in, may be null
@param repl the String to search for, may be null
@param with the String to replace with, may be null
@return the text with any replacements processed,
null if null String input
@see #replace(String text, String repl, String with, int max)
public static String replace(String text, String repl, String with)

20、

Replaces a String with another String inside a larger String,

for the first max values of the search String.


A null reference passed to this method is a no-op.


以指定字符串最大替换原来字符串的的指定字符串 StringUtils.replace(null, *, *, *) = null StringUtils.replace("", *, *, *) = "" StringUtils.replace("abaa", null, null, 1) = "abaa" StringUtils.replace("abaa", null, null, 1) = "abaa" StringUtils.replace("abaa", "a", null, 1) = "abaa" StringUtils.replace("abaa", "a", "", 1) = "abaa" StringUtils.replace("abaa", "a", "z", 0) = "abaa" StringUtils.replace("abaa", "a", "z", 1) = "zbaa" StringUtils.replace("abaa", "a", "z", 2) = "zbza" StringUtils.replace("abaa", "a", "z", -1) = "zbzz"

@param text text to search and replace in, may be null
@param repl the String to search for, may be null
@param with the String to replace with, may be null
@param max maximum number of values to replace, or -1 if no maximum
@return the text with any replacements processed,
null if null String input
public static String replace(String text, String repl, String with, int max)

你可能感兴趣的:(类,职场,StringUtils,休闲)