Home > DeveloperSection > Forums > Special character remove from url or any string
Rajesh Goswami

Total Post:29

Points:47
Posted on    December-06-2010 12:04 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 2911  View(s)
Rate this:
how we remove the special character from any string 
for example
string sSpecailChar="rajesh have $280.00 Rs. only, What!?"
in this sample how remove the special character like $!.?
is the best solution of this problem


Amit Singh

Total Post:103

Points:673
Posted on    December-06-2010 1:01 AM

we use regex class which contain many important properties like relace(), split(), match() etc
we remove the special char from any string
for example:
firstly, we use System.Text.RegularExpressions namespce

string strData = "rajesh have $280.00 Rs. only, What!?";
        string pattern = "[^a-zA-Z0-9]+";
        Regex rgx = new Regex(pattern);
        Response.Write("<font color='green'>Before Replace: </font> " + strData+"<br/>");
        Response.Write("<font color='green'>After Repalce: </font>" + rgx.Replace(strData, " "));

output:
Untitled PageBefore Replace: rajesh have $280.00 Rs. only, What!?
After Repalce: rajesh have 280 00 Rs only What















Recent Activities

jayprakash sharma Created New Discussion what is short circuit operator in java   8 hours ago

Sumit Kesarwani added new Question What is the Vector class in java?   2 days ago

Anchal Kesharwani added new Blog JSON Syntax   9 days ago

Anchal Kesharwani added new Article How to Send Mail in Node.JS   9 days ago

Top Contributors

Don't want to miss updates? Please click the below button!