Replace certain characters in a string

  • Thread starter Thread starter Fred Boer
  • Start date Start date
F

Fred Boer

Hello!

I am working with a string of known length. I wish to replace any occurance
of characters with ASCII values below 32 with a single character (say a
dollar sign...). Could someone please suggest an efficient method to do
this?

Thank you!
Fred Boer
 
I am not sure if you are wanting to go through every record ( would need to
use a recordset ) or just do this on a command button for a certain record,
but here are some air quotes to get you started...I think it should work ,
but I haven't tested it.:

dim i as integer
i = 0
do while i < 32
me.textfield = replace(me.textfield, Chr(i), "$")
i = i + 1
loop
 
Public Function RemoveChrs(strBad) As String
Dim i As Integer

For i = 1 To Len(strBad)
If Asc(Mid(strBad, i, 1)) <= 32 Then
Mid(strBad, i, 1) = "$"
End If
Next i
RemoveChrs = strBad

End Function
 
Back
Top