No Free Time

Because my therapist says I need to let things out

Archive for April 6th, 2008

Strip special characters (including spaces) from a string using Regex

Posted by andrewmyhre on April 6, 2008

This is the regex I use to convert a free text value to a filename style value (used in my CMS to create a filename based on a page title):

string cleanName = new Regex(“\W”).Replace(uncleanName, “”)

e.g: new Regex(“\W”).Replace(“page & title $ with %bad characters!!”, “”) = “pagetitlewithbadcharacters”

Posted in Uncategorized | Tagged: , | Leave a Comment »