String.ReplaceFirst(String, String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Replaces the first substring of this string that matches the given regular expression with the given replacement.
[Android.Runtime.Register("replaceFirst", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "")]
public string ReplaceFirst (string regex, string replacement);
[<Android.Runtime.Register("replaceFirst", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", "")>]
member this.ReplaceFirst : 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 the first match
Returns
The resulting String
- Attributes
Exceptions
if regularExpression == null
Remarks
Replaces the first substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceFirst(
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#replaceFirst replaceFirst}(<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#replaceFirst
. 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.replaceFirst(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.