endrec
asked on
Find and Replace (or Convert) Non-Ascii Characters In A String
Hi everyone. I'm definately not a VB.NET or developer pro, but I wanted to know if anyone has a function that removes non-ascii characters from a string/CSV readline.
I'm trying to find something that finds non-ascii characters and replace them with a space or attempt to convert them to ascii (I don't know if this is possible).
I'm trying to find something that finds non-ascii characters and replace them with a space or attempt to convert them to ascii (I don't know if this is possible).
Hi endrec;
This example code will remove all non printable characters from the input string and replace them with a space character.
Imports System.Text.RegularExpress ions
' Class level variable
Private re As New Regex("[\x00-\x1F\x7F-\xFF ]+", RegexOptions.Compiled)
Dim input As String ' String that will be striped of all non printable characters.
input = re.Replace(input, " ")
Input string should now have only printable characters in it.
Fernando
This example code will remove all non printable characters from the input string and replace them with a space character.
Imports System.Text.RegularExpress
' Class level variable
Private re As New Regex("[\x00-\x1F\x7F-\xFF
Dim input As String ' String that will be striped of all non printable characters.
input = re.Replace(input, " ")
Input string should now have only printable characters in it.
Fernando
ASKER
How would I remove non-standard ASCII characters (e.g. any of those characters in the extended ascii set and any non-printable characters)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you say non-ascii characters what do you mean?
For example the ASCII character set defines all characters between &H0 through &HFF, 0 - 255 decimal, but not all are printable. Which characters do you want to replace?
Fernando