Home Notices Documents Classes Download Others Rice
Classes  >  regex  >  Replace(string,string)
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

ClassNameDescription
stringsourceA string which is searched.
stringreplaceA string which replaced.

Return value

ClassDescription
stringA 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.

Links for reference

Copyright © Rice All rights reserved.