다음을 통해 공유


String.ReplaceAll(String, String) Method

Definition

Replaces each substring of this string that matches the given regular expression with the given replacement.

[Android.Runtime.Register("replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "")]
public string ReplaceAll (string regex, string replacement);
[<Android.Runtime.Register("replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "")>]
member this.ReplaceAll : string * string -> string

Parameters

regex
String

the regular expression to which this string is to be matched

replacement
String

the string to be substituted for each match

Returns

The resulting String

Attributes

Exceptions

if regularExpression == null

Remarks

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

<blockquote> {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile compile}(<i>regex</i>).{@link java.util.regex.Pattern#matcher(java.lang.CharSequence) matcher}(<i>str</i>).{@link java.util.regex.Matcher#replaceAll replaceAll}(<i>repl</i>) </blockquote>

Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; see java.util.regex.Matcher#replaceAll Matcher.replaceAll. Use java.util.regex.Matcher#quoteReplacement to suppress the special meaning of these characters, if desired.

Added in 1.4.

Java documentation for java.lang.String.replaceAll(java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also