Monday 25 February, 2008

Replace mupltiple Characters from the string

How to Replace mupltiple Characters from the string to a specific character?
How to Replace Special Characters like *,?, /, \, <, >, :, |," from the string to a specific character?


Use following in your C# code
//import RegularExpressions
using System.Text.RegularExpressions;

//Now use
Regex.Replace("Orginal String ","Find Characters from the string","Replace with the string");
for e.g.
//I want to replace four character '*'(star) and ','(comma) and ' '(space) and ':'(colon)
Regex.Replace("Str: I, also wants *","[*, :]","-");
System.Console.WriteLine("Str: I, also wants *");
System.Console.WriteLine(Regex.Replace("Str: I, also wants *","[*, :]","-"));

//output
Str: I, also wants *
Str- I- also wants -

No comments:

Hits4Pay