Skip to main content

Certain characters are not allowed when creating files & folders in the OS. So if you pick data from some source and then use it to create files/folders without any validation, there's a good chance things will fail because of these special characters (see below for an example in Windows). It would be great to have a string function and transformer that will clean up a string to ensure it is compliant with these restrictions (maybe a way to also map to whether certain characters are just removed vs. replaced with a character such as an underscore, etc.). Currently this is doable with a series of nested ReplaceString or ReplaceRegEx functions for example, but not as easy to format each time you need to do this. This function & "cleaner" transformer would simplify such tasks and ensure you have no failures in your translations and data writing tasks.


Here is an example I put together recently to clean up such strings once I started having failures and realized what the problem was. It works, but hard to read and edit, a pain with escaping of certain characters, etc. You just don't want to keep dealing with this every time you need to write a file/folder :) The shorters route was to use a ReplceRegEx function. It is nested 3 times because I wanted certain characters to be replaced by a space (long story as to why that <br/> is there in the first place), some by an underscore, and some removed altogether.

 

@ReplaceRegEx(@ReplaceRegEx(@ReplaceRegEx(@Value(MyString),"<br/>"," "),\\\\|/,_),"\\?|:|;|\\*|\\"|,|\\.","")