Clearing special ascii characters from a string

besides using replace(string,chr(235)," ")

what else could I use to replace ascii extended characters out of a string?
LVL 8
thenoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
You could do something like this:

Function CleanString(SourceString As String) As String

    Dim L As Long
    Dim TestChar As String

    Const LastAscii As Long = 126

    For L = 1 To Len(SourceString)
        TestChar = Mid(SourceString, L, 1)
        If Asc(TestChar) <= LastAscii Then CleanString = CleanString & TestChar
    Next

End Function
0
thenoneAuthor Commented:
good evening Mathew what if I have more than one ascii character to replace?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MilanKMCommented:
take a look at http://www.devx.com/vb2themax/Tip/19010

Hope this helps
MilanKM
0
clarkscottCommented:
I like to write these types of functions 'long hand' so I can deal with different situations.

==========================================
Function CheckText(byref YourText as string) as string
Dim L as long
L = len(YourText)
dim vNewText as string
Dim J as long
for J = 1 to L
    If mid(YourText,J,1) = chr(13) then '--- carriage return
          '---- do nothing
    elseif mid(yourText,J,1) = " " then '--- space
          '---- do nothing
    else
       vNewText = vNewText & mid(YourText,J,1)
    end if
next j

CheckText = vNewText

end function
==================================

Of course, a SELECT CASE could work instead of the IF...THEN....ELSE.

Scott C.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Patrick MatthewsCommented:
thenone,

> good evening Mathew what if I have more than one ascii character to replace?

The function I submitted will remove anything from the extended ASCII set (which is everything
from 128 on; I set the code to start excluding at 127 because it is not an English language
character).

Patrick
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.