Is there a good RegEx expression for changing non-valid alphanumeric characters in a string to " "?

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have a poitionally delimited flat file (.txt) with large records being
prepared for uploading to a mainframe. I need to make sure that any invalid
characters within fields are translated into spaces. It seems as though
RegEx might be most appropriate for this.

Does anyone know the RegEx syntax?
 
I bought the following book authored by Ben Forta a very well-known
and highly respected developer/author working for the enemy
-- Macromedia ;-) -- and highly recommend this book as it is the
best explanation of regular expression syntax I have ever read....

http://www.amazon.com/exec/obidos/t...i3_xgl14/104-8430504-5398335?v=glance&s=books

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
 
Tom said:
I have a poitionally delimited flat file (.txt) with large records being
prepared for uploading to a mainframe. I need to make sure that any invalid
characters within fields are translated into spaces. It seems as though
RegEx might be most appropriate for this.

Does anyone know the RegEx syntax?

The character class \W matches "any nonword character" - anything that is
not a-z, A-Z, or 0-9. So:

string foo = "hey!fix?this";
string bar = System.Text.RegularExpressions.Regex.Replace(foo, @"\W", "
");

You can buy a book, but I think the MSDN documentation on regular
expressions is pretty good.

Erik
 
Back
Top