replace是替换char类型的 替换String要用replaceAll String s = "abccc"; String t = s.replaceAll("ccc","xxx"); t的值就是"abxxx"
fft123(专杀各类日本畜生) 在jdk上的 Class String中找不到replaceAll()啊,好象js中有这个方法 java 中可以这样吗?
不会没有replaceAll函数啊??你的是哪个版本的jdk??1.3的?public String replaceAll(String regex, String replacement) Replaces each substring of this string that matches the given regular expression with the given replacement. An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters: regex - the regular expression to which this string is to be matched Returns: The resulting String Throws: PatternSyntaxException - if the regular expression's syntax is invalid NullPointerException - if regex is null Since: 1.4 See Also: Pattern
替换String要用replaceAll
String s = "abccc";
String t = s.replaceAll("ccc","xxx");
t的值就是"abxxx"
java 中可以这样吗?
String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
regex - the regular expression to which this string is to be matched
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
NullPointerException - if regex is null
Since:
1.4
See Also:
Pattern