|
-
Sep 21st, 2007, 01:22 AM
#1
Thread Starter
Hyperactive Member
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.", "")
-
Sep 21st, 2007, 01:55 AM
#2
PowerPoster
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
-
Sep 21st, 2007, 01:57 AM
#3
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.", "")
-
Sep 21st, 2007, 08:07 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|