I need to remove non printable characters from various textarea’s. Most importantly, linefeed and carriage returns.
I suck at regex! I do have one to replace any non alpha numeric characters. What would I use in the code below for a search pattern to just remove control codes?
Dim reg as new RegEx
reg.searchPattern = "[^a-zA-Z0-9]"
reg.replacementPattern = ""
reg.Options.ReplaceAllMatches = True
Dim source as string = item
Dim result as string = reg.replace( source )
Return result
matches any non-printable character, including control codes like linefeed (\n), carriage return (\r), and other non-printable ASCII characters.
If you want to be even more specific and only remove the control characters (ASCII 0-31) and keep the printable ones, you can use this pattern instead: