This year has been all about migrating existing business objects to SharePoint 2010. Some of these projects required bulk processing and conversion into either SPFile or SPItem objects. While there are excellent third party tools like ShareGate that help people migrate existing content back and forth inside of SharePoint; it is not always an option in that one project you are spinning. This is a simple method I use to clean strings of illegal, and some bothersome, characters on the way into SharePoint from either file shares, Lotus Notes, old database, web … whatever the source, it’s a good idea to clean it up first.
Essentially just open your connection to your data source, iterate and store a list of objects with corresponding properties in a generic. For each string that serves as a file name or a title field you want to have a measure of control over, send the string to a method like this example cleanstring.txt and return it without problematic values.