Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

StripControlChars - Delete control characters in a string
[ All Languages » VB »  String]

Total Hit ( 1790)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
' Strip all control characters (ASCII code < 32)
'
' If the second argument is True or omitted,
' CR-LF pairs are preserved

Function StripControlChars(source As String, Optional KeepCRLF As Boolean = _
  True) As String
  Dim index As Long
  Dim bytes() As Byte
  
  ' the fastest way to process this string
  ' is copy it into an array of Bytes
  bytes() = source
  For index = 0 To UBound(bytes) Step 2
    ' if this is a control character
    If bytes(index) < 32 And bytes(index + 1) = 0 Then
      If Not KeepCRLF Or (bytes(index) <> 13 And bytes(index) <> 10) Then
        ' the user asked to trim CRLF or this
        ' character isn't a CR or a LF, so clear it
        bytes(index) = 0
      End If
    End If
  Next
  
  ' return this string, after filtering out all null chars
  StripControlChars = Replace(bytes(), vbNullChar, "")
      
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.