Clearing special ascii characters from a string

Posted on 2006-03-29
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 92

    Assisted Solution

    by:Patrick Matthews
    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
    LVL 8

    Author Comment

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

    Assisted Solution

    by:Naveen Swamy
    LVL 14

    Assisted Solution

    take a look at

    Hope this helps
    LVL 20

    Accepted Solution

    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 92

    Expert Comment

    by:Patrick Matthews

    > 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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    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…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now