Ok basically i need the quickest code to remove numbers and symbols from a list of words.
so if the list of words, say list1 contained the following
*/Rick122-
-(lemon)-
$%bvfl4745fdfg
i would be left with
Rick122
lemon
bvflfdfg
Hope this is clear.
Printable View
Ok basically i need the quickest code to remove numbers and symbols from a list of words.
so if the list of words, say list1 contained the following
*/Rick122-
-(lemon)-
$%bvfl4745fdfg
i would be left with
Rick122
lemon
bvflfdfg
Hope this is clear.
The quickest way would probably be to remove the unwanted characters before you add the string to the list. Since creating strings is a slow process in VB I think the following would be the quickest way.You could now add strings to the listbox like this:VB Code:
Public Function RemoveSymbols(str As String) As String Dim sNew As String, sChar As String Dim nCount As Long, n As Long, nCurrent As Long nCount = Len(str) sNew = Space$(nCount) For n = 1 To nCount sChar = Mid$(str, n, 1) If sChar Like "[a-zA-Z]" Then nCurrent = nCurrent + 1 Mid$(sNew, nCurrent) = sChar End If Next RemoveSymbols = RTrim$(sNew) End FunctionVB Code:
List1.AddItem RemoveSymbols("*/Rick122-")
If you can't do what Joachim suggests then do this for each entry in the list, where TESTDATA is the list entry.
VB Code:
Dim lngIndex As Long Dim strOut As String For lngIndex = 1 To Len(TESTDATA) Select Case Asc(Mid$(TESTDATA, lngIndex, 1)) Case 97 To 122, 65 To 90, 48 To 57 strOut = strOut & Mid$(TESTDATA, lngIndex, 1) End Select Next MsgBox strOut