.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

How to remove the special Characters in string in c#.net?

Posted By: chandrakant     Posted Date: August 04, 2011    Points:5   Category :C#
How to remove the special Characters in string in c#.net? my string are ???C:\Documents and Settings\Administrator\Desktop\Time Sheet_Chandrakant_Kadu.xls???

I want to remove the special char from above string,
please help me

Thanks in advance

Author: Amit Mehra             
Posted Date: August 04, 2011     Points: 20   


In the above string there are 4 /:?. special characters are there. you want to remove all 4 or only question mark?
If you want to remove only only 1 special character than you can use below code

string str = "???C:\Documents and Settings\Administrator\Desktop\Time Sheet_Chandrakant_Kadu.xls???";
string myStr = str.Replace("?","");

If you want to remove all the 4 special characters than you can use below function

public static string RemoveSpecialCharacters(string str) {
StringBuilder sb = new StringBuilder();
foreach (char c in str) {
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') | || (c >= 'a' && c <= 'z')) {
return sb.ToString();

Ref stack overflow

Please "Mark As Answer " if this post help you.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend