Posts

Showing posts with the label Replace

C# Extension Methods

C#.NET comes with a lot of string processing methods like Substring , Compare , IndexOf , Replace , etc. Although the number and scope of such methods are vast, programmers still constantly have to rewrite similar text processing methods over and over again to suit their needs. Luckily we can extend on them and create all kinds of advanced string methods in C#. public string Replace ( string oldChar, string newChar) public string Replace ( string oldString, string newString) We will focus on Replace method here. In C#, Replace method has the following two signatures: Replace method does not give us the flexibility to replace after/from a specified position in a string or to replace for a specified number of occurrences within the string. This was possible in VB6. So, especially in migration projects there arises a need where we need to have extension methods of Replace. The signature of the extension methods we will create are as follows: public s