Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hidden characters 2

Status
Not open for further replies.

stephenk1973

Technical User
Jun 11, 2003
246
GB
Is there a way of querying on hidden characters.

Users have pasted into a memo field and all sort of hidden 'line feeds' and 'return carridge' characters have come accross confusing the uses in display.

How can i pick these out?

Thanks

Stephen
 
You could check the characters one by one to see if they conform to acceptable characters for your memo.

Code:
For i = 1 To Len(strMemo)
intAsc = Asc(Mid(strMemo, i, 1))
    If intAsc < 33 Or intAsc > 125 Then
        'Not allowed
    Else
        strMemo2 = strMemo2 & Chr(intAsc)
    End If
Next
 
How about using the Replace command to get rid of these characters:
Code:
replace(strMyString,chr(13),"")

Adapting Remou's code you could do a loop through a range of ASCII characters that are not acceptable, something like:
Code:
For i = 1 to 33
   Replace(strMyString, chr(i),"")
Next i
 
I use the following on the before update event of the form to avoid this.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  If Not IsNull(Me.Title) Then
    Me.Title = fncStripSpecial(Me.Title)
  End If
End Sub

here is my function. You can use any of the other ones given. The point is that you push in a "dirty" string and return a cleaned up string before you update.

Code:
Public Function fncStripSpecial(strStrip As String) As String
   'Strip front
   Do While Asc(strStrip) <= 32
    strStrip = Mid(strStrip, 2)
   Loop
    'Strip back
   Do While Asc(Right(strStrip, 1)) <= 32
     strStrip = Left(strStrip, Len(strStrip) - 1)
   Loop
   fncStripSpecial = strStrip
End Function
 
I used the above only to strip off the ends so that the user could have formatting within the memo. Here is one to get rid of all. Kind of the same as Remou's and Joe's
Code:
Public Function fncStripSpecial(strStrip As String) as string
   Dim n As Integer
   For n = 1 To 32
      strStrip = Replace(strStrip, Chr(n), "")
   Next n
   fncStripSpecial = strStrip
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top