Results 1 to 4 of 4

Thread: Remove all numbers, emails and web addresses?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Posts
    360

    Exclamation Remove all numbers, emails and web addresses?

    Im trying to remove all numbers, emails and web addresses from a string.


    This is kind of what im doing now which I think is ridiculous, there's got to be an easier way to remove all numbers.... with less code.


    OldString = Replace(NewString, "0", "")
    OldString = Replace(NewString, "1", "")
    OldString = Replace(NewString, "2", "")
    OldString = Replace(NewString, "3", "")
    OldString = Replace(NewString, "4", "")
    OldString = Replace(NewString, "5", "")
    OldString = Replace(NewString, "6", "")
    OldString = Replace(NewString, "7", "")
    OldString = Replace(NewString, "8", "")
    OldString = Replace(NewString, ".com", "")
    OldString = Replace(NewString, ".net", "")
    OldString = Replace(NewString, "www.", "")

  2. #2
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Remove all numbers, emails and web addresses?

    Try this: not tested though

    Code:
    Dim ArrExclude
    Dim i As Integer
    
    ArrExclude = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".com", ".net", "www")
    
    
    For i = 0 To ubound(ArrExclude())        
            If InStr(1, NewString, ArrExclude(i)) Then
                
                   use the replace commands here!!!!
                  
           End If
        
    Next i

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Remove all numbers, emails and web addresses?

    With your way, you should do like this:

    Code:
    NewString = Replace(OldString, "0", "")
    NewString = Replace(NewString, "1", "")
    NewString = Replace(NewString, "2", "")
    NewString = Replace(NewString, "3", "")
    NewString = Replace(NewString, "4", "")
    NewString = Replace(NewString, "5", "")
    NewString = Replace(NewString, "6", "")
    NewString = Replace(NewString, "7", "")
    NewString = Replace(NewString, "8", "")
    NewString = Replace(NewString, "9", "")
    NewString = Replace(NewString, ".com", "")
    NewString = Replace(NewString, ".net", "")
    NewString = Replace(NewString, "www.", "")
    For shorter code:
    Code:
    Dim arFilter as Variant
    Dim i as Integer
    
    arFilter = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".com", ".net", "www.")
    NewString = OldString
    For i = 0 to 12
       NewString = Replace(NewString, arFilter(i), "")
    Next
    or
    Code:
    Dim i as Integer
    
    NewString = OldString
    For i = 0 to 9
       NewString = Replace(NewString, "" & i, "")
    Next
    NewString = Replace(NewString, ".com", "")
    NewString = Replace(NewString, ".net", "")
    NewString = Replace(NewString, "www.", "")

  4. #4
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: Remove all numbers, emails and web addresses?

    You probably will find it best to add the Regular Expressions component to your project and use it for this kind of complex parsing. Here's an article that describes how to do it: http://www.regular-expressions.info/vb.html

Posting Permissions

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



Click Here to Expand Forum to Full Width