Results 1 to 3 of 3

Thread: [RESOLVED] Strings help

  1. #1

    Thread Starter
    Hyperactive Member jlt7's Avatar
    Join Date
    Jan 2006
    Posts
    413

    Resolved [RESOLVED] Strings help

    I have this in a database

    Start§Claire Danes|Yvaine|0000132#§Sienna Miller|Victoria|1092227#§Ricky Gervais|Ferdy the Fence|0315041#§Jason Flemyng|Primus|0002076#§Mark Strong|Septimus|0835016#§Rupert Everett|Secundus|0000391#§Charlie Cox|Tristan Thorn|1214435#§Michelle Pfeiffer|Lamia|0000201#§Robert De Niro|Captain Shakespeare|0000134#§Sarah Alexander|Empusa|0018729#§Melanie Hill|Ditchwater Sal|0384514#§Joanna Scanlan|Mormo|0768936#§Kate Magowan|Slave Girl - Una|0536461#§Peter O'Toole|King|0000564#§David Kelly|Guard|0446303#End

    and I this is my code.

    Code:
    Public Function Actors()
    Dim lonPos As Long, lonEnd As Long
    Dim strStart As String, strEnd, strInfo As String
    Dim strSAct As String, strEAct, strName As String
    
        mystring = frmMain.Data
        tempString = Split(mystring, "#")
        num = UBound(tempString)
            
        strStart = "Start"
        strEnd = "End"
    
        lonPos = InStr(1, frmMain.Data, strStart, vbTextCompare)
    
        If lonPos > 0 Then
            lonPos = lonPos + Len(strStart)
        
            lonEnd = InStr(lonPos, frmMain.Data, strEnd, vbTextCompare)
        
            If lonEnd > 0 Then
                strInfo = Mid$(frmMain.Data, lonPos, lonEnd - lonPos)
            End If
        End If
        
        
        For i = 1 To num
            strSAct = "§"
            strEAct = "#"
    
            lonPos = InStr(1, strInfo, strSAct, vbTextCompare)
    
            If lonPos > 0 Then
                lonPos = lonPos + Len(strSAct)
        
                lonEnd = InStr(lonPos, strInfo, strEAct, vbTextCompare)
        
                If lonEnd > 0 Then
                    strName = Mid$(strInfo, lonPos, lonEnd - lonPos)
                End If
            End If
        Next i
        
    
            Set a = frmMain.lstCast.ListItems.Add(, , strName)
            
    End Function
    I'm not sure if this can be done but if it can be done can someone help me out.

    I have it count the # in the string so that is how many there will be in the listview. and then I want it to loop thru the string from the § to # and separate each one into the different listitems.

    I'm not sure if I need an array and if so how do I do that or if I can loop thru it and split it somehow. pls someone help me out on what I can do.

    thanks

    basically it will separate like so:
    Claire Danes|Yvaine|0000132
    Sienna Miller|Victoria|1092227

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Strings help

    One of the secrets of string manipulation/parsing is you don't have to limit your algorithm to the string as it is (in its original form), you can make copies. Modify the string (copy most of the time) accordingly, as long as the data you need from the string remains intact. If there are extraneous characters then git rid of them if it will make parsing easier... If you need to iterate through data in the string then consider converting it to an array... etc, etc

    Get rid of Start§ and #End.
    Code:
     Mid(yourStr, 7, Len(yourStr) - 10)
    Transfer from string to string array
    Code:
    Dim strLines() As String
    
    strLines = Split(yourString, "#" & Chr(167))
    Just iterate through the array if you need to transfer to list control
    Code:
    Dim i As Long
    For i = 0 To Ubound(strLines)
       'update code in iteration according to your needs
       Debug.Print strLines(i)     
    Next
    Last edited by leinad31; Feb 21st, 2008 at 07:07 PM.

  3. #3

    Thread Starter
    Hyperactive Member jlt7's Avatar
    Join Date
    Jan 2006
    Posts
    413

    Re: Strings help

    Thanks leinad31, I finally got it working.

    Thank you very much

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