Remove non-ASCII Characters

Are you getting those funky characters from your database that are screwing up things like your XML feed? If you're using ColdFusion, there's an easy fix. Use a regular expression replace function to get rid of those pesky non-ASCII characters.

REReplace(inputString, "[^\x00-\x7F]", " ", "ALL")

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Ryan Stille's Gravatar This will remove all characters but those in the 0-127 range ("low ascii"). There are a few characters in this range that you still won't want though, for example ascii code 11, a vertical tab. I've encountered this when processing data that was imported from Excel. It then caused my XML parser to choke. I'm sure there are others. What I allowed in were ascii codes 9, 10, 13 and 32-126. My function was about 15 lines, I like your approach better though, its much shorter.
# Posted By Ryan Stille | 11/10/08 11:12 PM
Nick Tong's Gravatar Works well - thanks
# Posted By Nick Tong | 11/27/08 4:40 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner