Replacing all the occurences of a string with new value
In a string text, if some texts which occur at many places, need to be replaced by some different value then a regular expression can be used.This can be done by using System.Text.RegularExpressions.Regex class of .NET framework.
For example suppose a string variable str contains "This is <
using System.Text.RegularExpressions;
class ReplaceDemo
{
public string ReplaceName(string originalText,string name)
{
originalText =Regex.Replace(originalText, <
}
}
The above "ReplaceName()" function will return the following value if passed the string str and "DOTNETSPIDER" in the function -
"This is DOTNETSPIDER and it used by the regex class.The value for DOTNETSPIDER will be replaced."
It is clear that all the occurences of <