[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Clearing special ascii characters from a string

Posted on 2006-03-29
Medium Priority
Last Modified: 2010-04-07
besides using replace(string,chr(235)," ")

what else could I use to replace ascii extended characters out of a string?
Question by:thenone
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 1200 total points
ID: 16328403
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

End Function

Author Comment

ID: 16329109
good evening Mathew what if I have more than one ascii character to replace?

Assisted Solution

by:Naveen Swamy
Naveen Swamy earned 200 total points
ID: 16329560
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 14

Assisted Solution

MilanKM earned 200 total points
ID: 16329601
take a look at http://www.devx.com/vb2themax/Tip/19010

Hope this helps
LVL 20

Accepted Solution

clarkscott earned 400 total points
ID: 16331217
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
       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.

LVL 93

Expert Comment

by:Patrick Matthews
ID: 16331505

> 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


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question