Replace certain characters in a string

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
 
T

tiger0268 via AccessMonster.com

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
 
K

Klatuu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top