?
Solved

removing non-alphabetical and non-numeric chars from a string?

Posted on 2005-04-13
4
Medium Priority
?
388 Views
Last Modified: 2012-05-05
Is there a way to remove all non alphabetical and non numeric chars from some string.
thanks
0
Comment
Question by:Carl3003
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 13777195
Hi Carl3003,

Well, here's one way.  This assumes that the initial string is called strInput.

    For x = 1 To Len(strInput)
        Select Case Asc(Mid(strInput, x, 1))
            Case 48 To 57, 65 To 90, 97 To 122
                strOutput = strOutput & Mid(strInput, x, 1)
        End Select
    Next


Cheers!
0
 
LVL 12

Assisted Solution

by:GoofyDawg
GoofyDawg earned 500 total points
ID: 13777282
I think this'll work, but you probably test it.

function stripNonAlphaNumericChars(strng)
  dim regex, match, matches
  set regex = new regexp
  regex.pattern = "\w" 'match all chars, including the underscore
  regex.ignorecase = true
  regex.global = true
  set matches = regex.execute(strng)
  for each match in matches
    retstr = retstr & match.value
  next
 
  'to remove the underscore, you have to do another match for that...
  regex.pattern = "_" 'match all chars, including the underscore
  regex.ignorecase = true
  regex.global = true
  retstr = regex.replace(retstr, "")
  set regex = nothing
  regexptest = retstr
end function

GoofyDawg
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 13779771
Goofydawg just about has it.  RegEx has a replace function and you can combine the expressions to do it all in one hit

      Function cleanTerm(strString)
            Dim objRegExp
            Set objRegExp = New RegExp
            objRegExp.Pattern = "[/w_]"
            objRegExp.IgnoreCase = True
            objRegExp.Global = True
            cleanterm = ObjRegExp.Replace(strString, "")
            Set objRegExp = Nothing
      End Function

That shoudl do the trick - I just modified a function I use a lot myself

HTH

C
0
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 13839706
Nice, snavebelac... haven't used RegEx in a long time... forgot about being able to combine them... took the safe route.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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