The below method will replace all special or escape characters in a provided String.
This is of use, if you have to use before unknown Strings from any source for example in a file name.
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
' @Author - Alexander Bolte' @Description - replaces all characters, which match the pattern "[^A-Za-z0-9-_ ]" in a given String.' @Param aText - a String in which invalid characters should be replaced.' Returns the handed String from aText excluding all replaced characters.PublicFunctionreplaceSpecialCharacters(ByValaTextAsString)AsStringDimregExAsNewRegExpConstcReplEscapeCharAsString="[^A-Za-z0-9-_ ]"regEx.pattern=cReplEscapeCharregEx.Global=TrueregEx.IgnoreCase=TrueaText=regEx.Replace(aText,"")replaceSpecialCharacters=aTextEndFunction