Results 1 to 4 of 4

Thread: parsing a string

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Could someone give me the code to
    parse this string into two at the "["
    from the right..

    "[Michelle] nice meeting you Evan, let's get down to buisness
    [Michelle] ok"

    I would like to parse it too this

    "[Michelle] ok"

    Thanks!



  2. #2
    Guest
    I don't really get what you're trying to do. Please elaborate.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Its Easy,

    I would like to take part the a
    string and put it in another string
    .. By the character of [

  4. #4
    Guest
    Try this:

    Code:
    Public Function ParseString(ByVal vsString As _
    String, ByVal vsDelimiter As String, ByVal _
    viNumber As Integer)
    
    'Author: Steve Anderson
    'Created : 13/08/98
    'Purpose : Parses out a section
    'from a delimited string
    
    Dim iFoundat As Integer
    Dim iFoundatold As Integer
    Dim iCurrentSection As Integer
    Dim sText As String
    If Len(vsString) > 0 And InStr(vsString, _
    vsDelimiter) > 0 And viNumber > 0 Then
      iFoundat = 1
      iFoundatold = 1
      Do While InStr(iFoundatold + 1, vsString, _
      vsDelimiter) > 0
      iFoundatold = iFoundat
      iFoundat = InStr(iFoundat + 1, vsString, _
      vsDelimiter)
      iCurrentSection = iCurrentSection + 1
      Loop
      If viNumber > iCurrentSection Then
        Exit Function
      End If
      iFoundat = 1
      iCurrentSection = 0
      Do
        iFoundatold = iFoundat
        iFoundat = InStr(iFoundat + 1, vsString, _
        vsDelimiter)
        If Trim(sText) = "" Then
          sText = Mid(vsString, 1, iFoundat - 1)
          iCurrentSection = iCurrentSection + 1
        Else
          If iFoundat > 0 Then
            sText = Mid(vsString, iFoundatold + 1, _
            (iFoundat - 1) - iFoundatold)
          Else
            sText = Mid(vsString, iFoundatold + 1)
          End If
          iCurrentSection = iCurrentSection + 1
        End If
        If iCurrentSection = viNumber Then
          ParseString = sText
          Exit Do
        End If
      Loop
    End If
    ParseString = sText
    End Function
    
    Usage:
    
    Private Sub Command1_Click()
    Dim strString As String
    
    strString = "[Michelle] nice meeting you Evan, let's get down to buisness [Michelle] ok"
    MsgBox ParseString(strString, "[", 2)
    End Sub

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