Link to home
Start Free TrialLog in
Avatar of endrec
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).
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi endrec;

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
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.RegularExpressions

    ' 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
Avatar of endrec
endrec

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
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial