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?
string[] oOriginalString = OriginalString.Split(cFndChars);
OR using single line code
OriginalString = string.Join("-",OriginalString.Split(new char[] {'*','/','\\','?','<','>',':','|','"'}));
C# Code
string funMultipleReplace(string OrgStr, char[] ReplChars)
{
//Here I have replace characters into "-". You can use your choice.
return string.Join("-",OrgStr.Split(ReplChars));
}
//---------
char[] cFndChars = {'*','/','\\','?','<','>',':','|','"'};
string oStr = "Original String: with * and ? params having < & >";
string ReplacedString = funMultipleReplace(oStr,cFndChars);
//Output before replace chars
Original String: with * and ? params having < & >
//Output after replace chars
Original String- with - and - params having - & -
No comments:
Post a Comment