Recent Posts

Thursday, January 21, 2010

Remove unprintable or invisible characters from string in VB.net

This function will help to remove all invisible characters in vb.net string

Public Function Remove(ByVal str As String) As String
        Remove = str
        Dim x As Long
        ' remove all non-printable characters
        While InStr(Remove, vbCrLf) > 0
            Remove = Replace(Remove, vbCrLf, String.Empty)
        End While

        While InStr(Remove, vbTab) > 0
            Remove = Replace(Remove, vbTab, String.Empty)
        End While

        For x = 0 To 31
            While InStr(Remove, Chr(x)) > 0
                Remove = Replace(Remove, Chr(x), String.Empty)
            End While
        Next x

        For x = 127 To 255
            While InStr(Remove, Chr(x)) > 0
                Remove = Replace(Remove, Chr(x), String.Empty)
            End While
        Next x

        'Dim s = New String(" ", 2)
        'While InStr(Remove, s) > 0
        '    Remove = Replace(Remove, s, " ")
        'End While
    End Function

Related Posts by Categories




2 comments:

rmouniak said...

It 's an amazing and Very Nice,Thanks for sharing
Dot Net Online Training Hyderabad

Janu said...

Keep up the good work; I read few posts on this website, including I consider that your blog is fascinating and has sets of the fantastic piece of information.



Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery



Post a Comment