Results 1 to 3 of 3

Thread: Removing Symbols and Numbers RESOLVED

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Resolved Removing Symbols and Numbers RESOLVED

    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.
    Last edited by Ricky1; Jan 10th, 2006 at 08:59 AM.
    Im Learning !!!!

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Removing Symbols and Numbers

    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.
    VB Code:
    1. Public Function RemoveSymbols(str As String) As String
    2.     Dim sNew As String, sChar As String
    3.     Dim nCount As Long, n As Long, nCurrent As Long
    4.     nCount = Len(str)
    5.     sNew = Space$(nCount)
    6.     For n = 1 To nCount
    7.         sChar = Mid$(str, n, 1)
    8.         If sChar Like "[a-zA-Z]" Then
    9.             nCurrent = nCurrent + 1
    10.             Mid$(sNew, nCurrent) = sChar
    11.         End If
    12.     Next
    13.     RemoveSymbols = RTrim$(sNew)
    14. End Function
    You could now add strings to the listbox like this:
    VB Code:
    1. List1.AddItem RemoveSymbols("*/Rick122-")

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Removing Symbols and Numbers

    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:
    1. Dim lngIndex As Long
    2. Dim strOut As String
    3.  
    4. For lngIndex = 1 To Len(TESTDATA)
    5.     Select Case Asc(Mid$(TESTDATA, lngIndex, 1))
    6.         Case 97 To 122, 65 To 90, 48 To 57
    7.             strOut = strOut & Mid$(TESTDATA, lngIndex, 1)
    8.     End Select
    9. Next
    10.  
    11. MsgBox strOut

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