Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Location
    Oklahoma
    Posts
    10

    Unanswered: VB function to remove Punctuation

    Anybody got a VB function that will remove all punctuation from a string?
    -Dustin
    Rom 8:28

  2. #2
    Join Date
    Sep 2002
    Location
    Land of OZ
    Posts
    173

    Re: VB function to remove Punctuation

    Combination of InStr and Mid .... Give me a string that you have with punctation and what you want re,oved and I will whip some code up for you ...

    Originally posted by Dustman
    Anybody got a VB function that will remove all punctuation from a string?
    Mona
    ________________________________
    Life is too short to be sane or sensible. Weird people rule and normal people suck

  3. #3
    Join Date
    Jan 2003
    Location
    Oklahoma
    Posts
    10
    Yeah, I know how to do it, I'm just so swamped with other modules right now that I don't have the time to concentrate on it. I figured somebody has some old code lying around or has the time to whip something up.

    It needs to remove all punctuation marks from the string (! - , . # ~ $ " ' ... everything). I'm having to modify a query that is used for mailing lables, the mailing dept is now requiring them to have absolutly no punctuation. I'm just going to change my query when its for mailing labels and grab each field with this function.. ie: SELECT StripP([SendTo]), StripP([AdrLn1]) FROM [AddressList];
    -Dustin
    Rom 8:28

  4. #4
    Join Date
    Jan 2003
    Location
    Oklahoma
    Posts
    10
    Got it, here's the code I'm using..

    Public Function StripP(Text As String) As String
    'Strips all punctuation from a string.
    Dim TxtLen, CheckChr, Counter As Long, CurChar, NewText As String

    Counter = 0
    TxtLen = Len(Text)

    Do While Counter < TxtLen
    Counter = Counter + 1
    CheckChr = Asc(Mid(Text, Counter, 1))
    Select Case CheckChr
    Case 32, 48 To 57, 65 To 90, 95, 97 To 122
    'Do Nothing
    Case Else
    Text = Left(Text, Counter - 1) & Right(Text, TxtLen - Counter)
    TxtLen = Len(Text)
    Counter = Counter - 1
    End Select
    Loop
    StripP = UCase(Text)
    End Function


    That will strip out everything but A-Z, a-z, 0-9, spaces and underscores. It will then send it back in all caps.
    -Dustin
    Rom 8:28

  5. #5
    Join Date
    Jan 2003
    Location
    Oklahoma
    Posts
    10
    One more thing, I had to add 10 and 13 to the case statement to let carriage returns and line feeds pass through.
    -Dustin
    Rom 8:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •