regex class : Replace(string,string) method
Description
Gets a new string that has replaced all strings that match the regular expression pattern in the argument.
Syntax
regexInstance.Replace(string source, string replace)
Arguments
Class | Name | Description |
string | source | A string which is searched. |
string | replace | A string which replaced. |
Return value
Class | Description |
string | A string after replacing. |
Sample code
1: | regex pattern = new regex("a+"); |
2: | string result = pattern.Replace("aaabbbaaccc", "ddd"); // The result is "dddbbbdddccc". |
Notes
It's a wrapper of the System.Text.RegularExpressions.Regex.Replace(String,String) method.