Remove unwanted characters from a string

PrimeNY used Ask the Experts™
I need to remove all characters from a string that are not letters, numbers or spaces?  Using a button click event in VB within a ASP.Net 2.0 website.

strOld = "Bill said "No" when he & Jim broke Joe's 1850 vase."

needs to be:

strNew = "Bill said No when he Jim broke Joes 1850 vase"

- Thanks

Asp.Net 2.0 /
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Use RegEx to replace all characters that do not match alphanumeric characters with an empty string.
I think it should be something like attached code.
stringToCleanUp = Regex.Replace(stringToCleanUp, "[^a-zA-Z0-9]", "")

Open in new window


You got me 95% there - just needed to add the space to the acceptable characters.  Thanks.

stringToCleanUp = Regex.Replace(stringToCleanUp, "[^a-zA-Z0-9 ]", "")
StephanLead Software Engineer

use \s

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial