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

x
?
Solved

Clearing special ascii characters from a string

Posted on 2006-03-29
6
Medium Priority
?
399 Views
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?
0
Comment
Question by:thenone
6 Comments
 
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
    Next

End Function
0
 
LVL 8

Author Comment

by:thenone
ID: 16329109
good evening Mathew what if I have more than one ascii character to replace?
0
 
LVL 9

Assisted Solution

by:Naveen Swamy
Naveen Swamy earned 200 total points
ID: 16329560
0
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

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

Hope this helps
MilanKM
0
 
LVL 20

Accepted Solution

by:
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
    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
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16331505
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

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