Results 1 to 17 of 17

Thread: [RESOLVED] split string help only few extracting

  1. #1

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Resolved [RESOLVED] split string help only few extracting

    data recieved.

    Code:
    @dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9
    it can be long or short.

    need to extract line by line

    Code:
    Dim PacketArray5() As String
    
    PacketArray5() = Split(Data, "%@")
    'Debug.Print PacketArray5(0)
    'Debug.Print PacketArray5(1)
    'Debug.Print PacketArray5(2)
    'Debug.Print PacketArray5(3)
    'Debug.Print PacketArray5(4)
    this is all in data arrival.
    only extracts one line so from harris fna all the way to end of the line of harris e2d1ef98-61d9

    post updaed to post6
    Last edited by jenniger9; Aug 11th, 2022 at 10:23 AM.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: split string help only few extracting

    And your problem is?
    Code:
    Sub main()
    Dim s As String
    Dim a() As String
    Dim i As Long
        s = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        a = Split(s, "%@")
        For i = LBound(a) To UBound(a)
            Debug.Print a(i)
        Next
    End Sub
    Returns:
    Code:
    @dE%GetHost#@
    harris fna
    men of war
    Text1.Text
    3/8
    e2d1ef98-61d9@dE%GetHost#@
    tamina
    men of war
    Text1.Text
    0/8
    e2d1ef98-61d9@dE%GetHost#@
    james
    men of war
    Text1.Text
    6/8
    e2d1ef98-61d9
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: split string help only few extracting

    I think i understand
    Code:
    Sub main()
    Dim s As String
    Dim t As String 'temp. String
    Dim d As String 'Delimiters
    Dim p As String 'Primary Delimiter
    Dim r As String 'remaining Delimiters
    Dim a() As String
    Dim i As Long
        d = "%@"
        p = Left$(d, 1)
        r = Mid$(d, 2)
        s = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        For i = 1 To Len(r)
            s = Replace(s, Mid$(r, i, 1), p)  'replace all remaining delimiters with the primary delimiter
        Next
        Do
            t = Replace(s, p & p, p)    'trim down consecutive delimiters until there is only one left
            If Len(t) = Len(s) Then
                Exit Do
            Else
                s = t
            End If
        Loop
        a = Split(s, p)
        For i = LBound(a) To UBound(a)
            Debug.Print a(i)
        Next
    End Sub
    Returns
    Code:
    dE
    GetHost#
    harris fna
    men of war
    Text1.Text
    3/8
    e2d1ef98-61d9
    dE
    GetHost#
    tamina
    men of war
    Text1.Text
    0/8
    e2d1ef98-61d9
    dE
    GetHost#
    james
    men of war
    Text1.Text
    6/8
    e2d1ef98-61d9
    Note: First Member of the Split --> a(0) is an empty string, since s starts with a delimiter

    EDIT: This is pure vb
    There is a way involving two API's (StrSpn and StrCSpn) but i would have to sit down to figure it out again
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: split string help only few extracting

    thank you guys can i have only

    Code:
    harris fna
    men of war
    Text1.Text
    3/8
    e2d1ef98-61d9
    tamina
    men of war
    Text1.Text
    0/8
    e2d1ef98-61d9
    james
    men of war
    Text1.Text
    6/8
    e2d1ef98-61d9
    removing and ignoring special chars or @dE%GetHost#@ or any code in data arrival.
    this data can be mix different names this is just a example data used

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,344

    Re: split string help only few extracting

    Use the replace function to remove unwanted strings of text from the input

  6. #6

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: split string help only few extracting


    ok this is what am doing.
    client is sending the listview items to the server


    Code:
    For i = 1 To frmChat.ListView1.ListItems.Count
    'If frmChat.ListView1.ListItems(i).Selected = True Then
    Call SendData("%@世" & frmChat.ListView1.ListItems(i).Text & "%@世" & frmChat.ListView1.ListItems.Item(i).ListSubItems.Item(1).Text & "%@世" & frmChat.ListView1.ListItems.Item(i).ListSubItems.Item(2).Text & "%@世" & frmChat.ListView1.ListItems.Item(i).ListSubItems.Item(3).Text & "%@世" & frmChat.ListView1.ListItems.Item(i).ListSubItems.Item(4).Text & "%@世")
    'Exit For
    'End If
    Next i
    ListView1.ListItems.Clear

    server
    server finds the data and sends to all client
    Code:
    If InStr(Data, "%@世") Then
    Debug.Print Data
     For I% = 1 To Ws().UBound
      Ws(I%).SendData Data
      Next I%
    End If


    back to client

    Code:
    If InStr(Data, "%@世") Then
    
    and here i wish to re add them in listview
    
     Dim ids As Integer
     ids = 0
     ids = ListView1.ListItems.Count + 1
     frmChat.ListView1.ListItems.Add , , "harris fna"      <<<<<<<<< replacing each line with data
     frmChat.ListView1.ListItems(ids).ListSubItems.Add , , "men of war" <<<<<<<<< replacing each line with data
     frmChat.ListView1.ListItems(ids).ListSubItems.Add , , "Text1.Text"   <<<<<<<<< replacing each line with data
    frmChat.ListView1.ListItems(ids).ListSubItems.Add , , "3/8"   <<<<<<<<< replacing each line with data
    frmChat.ListView1.ListItems(ids).ListSubItems.Add , , frmChat.List2.Text     <<<<<<<<< replacing each line with data
    
    End If
    here is the new string
    Code:
    %@世去arris fna%@世叮en of war%@世冉ext1.Text%@世3/8%@世占2d1ef98-61d9%@世孕%@世另amina%@世叮en of war%@世冉ext1.Text%@世0/8%@世占2d1ef98-61d9%@世孕%@世古ames%@世叮en of war%@世冉ext1.Text%@世6/8%@世占2d1ef98-61d9%@世
    it may seem like i already have data in listview dont worry about it. i just need to get the data i need rest i will manage
    Last edited by jenniger9; Aug 11th, 2022 at 10:34 AM.

  7. #7
    Junior Member
    Join Date
    Jun 2022
    Posts
    30

    Re: split string help only few extracting

    maybe

    Code:
    Dim s As StriNg
    Dim r As StrinG
        s = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        r = replaCe(s, "%@",vbCrLf)
       msgBox R
    End Sub
    or

    Code:
     Dim s As String
     Dim r As String
     Dim D As String
         D = "%@"
         s = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        s = s + D
         Do While s <> ""
                r = Mid(s, 1, InStr(s, D) - 1)
                MsgBox "_" + r + "_" 'your code
                s = Mid(s, InStr(s, D) + Len(D))
         Loop
    Last edited by sah1d; Aug 11th, 2022 at 10:38 AM.

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: split string help only few extracting

    Quote Originally Posted by jenniger9 View Post
    thank you guys can i have only

    Code:
    harris fna
    men of war
    Text1.Text
    3/8
    e2d1ef98-61d9
    tamina
    men of war
    Text1.Text
    0/8
    e2d1ef98-61d9
    james
    men of war
    Text1.Text
    6/8
    e2d1ef98-61d9
    removing and ignoring special chars or @dE%GetHost#@ or any code in data arrival.
    this data can be mix different names this is just a example data used
    Use my code in post 3, and ignore array-members you dont need
    its not rocket science
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  9. #9

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: split string help only few extracting

    Quote Originally Posted by Zvoni View Post
    Use my code in post 3, and ignore array-members you dont need
    its not rocket science
    can you check post6 how do i add it to my listview then

    dE <<<<< not needed
    GetHost# <<<<< not needed
    harris fna
    men of war
    Text1.Text
    3/8
    e2d1ef98-61d9
    dE <<<<< not needed
    GetHost# <<<<< not needed
    tamina
    men of war
    Text1.Text
    0/8
    e2d1ef98-61d9
    dE <<<<< not needed
    GetHost# <<<<< not needed
    james
    men of war
    Text1.Text
    6/8
    e2d1ef98-61d9

  10. #10
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: split string help only few extracting

    Run through the array using do/loop until you hit first GetHost,
    next array-member is user hosting
    next array-member is game name
    next array-member is game description
    next array-member is user-count
    next array-member is server
    set iterator-variable to the next value, and loop until next GetHost and so on

    as i said: no rocket science
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  11. #11

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: split string help only few extracting

    something like this but it adds all same value from 1 string

    Code:
    Private Sub Command1_Click()
    Text1.Text = ""
    ListView1.ListItems.Clear
    Dim s As String
    Dim a() As String
    Dim i As Long
        s = "%@世去arris fna%@世叮en of war%@世冉ext1.Text%@世3/8%@世占2d1ef98-61d9%@世孕%@世另amina%@世叮en of war%@世冉ext1.Text%@世0/8%@世占2d1ef98-61d9%@世孕%@世古ames%@世叮en of war%@世冉ext1.Text%@世6/8%@世占2d1ef98-61d9%@世"
        
    Dim PacketArray2() As String
    PacketArray2() = Split(s, "%@世")
    
    
    
        For i = LBound(PacketArray2) To UBound(PacketArray2)
        
            Debug.Print PacketArray2(i)
            Text1.Text = Text1.Text & PacketArray2(i)
            
             ids = 0
             On Error Resume Next
     ids = ListView1.ListItems.Count + 1
     'Ids: Increment ListView Row Index for Next Record
    ListView1.ListItems.Add , , PacketArray2(1)
     ListView1.ListItems(i).ListSubItems.Add , , PacketArray2(2)
     ListView1.ListItems(i).ListSubItems.Add , , PacketArray2(3)
    ListView1.ListItems(i).ListSubItems.Add , , PacketArray2(4)
    ListView1.ListItems(i).ListSubItems.Add , , PacketArray2(5)
        Next i
        
    End Sub

  12. #12

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: split string help only few extracting

    Quote Originally Posted by Zvoni View Post
    Run through the array using do/loop until you hit first GetHost,
    next array-member is user hosting
    next array-member is game name
    next array-member is game description
    next array-member is user-count
    next array-member is server
    set iterator-variable to the next value, and loop until next GetHost and so on

    as i said: no rocket science
    buddy. thanks for the advise and yeah really bro if i know post10 than i would have done it am just reading and thinking how to do it.

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: split string help only few extracting

    I can help you tomorrow from my workplace (no VB at home)
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  14. #14

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: split string help only few extracting

    also this needs fixing ads same value

    Code:
    Private Sub Command3_Click()
    Dim strUsers() As String
    ListView1.ListItems.Clear
    Dim i As Integer
    s = "%@世去arris fna%@世叮en of war%@世冉ext1.Text%@世3/8%@世占2d1ef98-61d9%@世孕%@世另amina%@世叮en of war%@世冉ext1.Text%@世0/8%@世占2d1ef98-61d9%@世孕%@世古ames%@世叮en of war%@世冉ext1.Text%@世6/8%@世占2d1ef98-61d9%@世"
    strUsers$ = Split(s, "%@世")
    For i% = 1 To UBound(strUsers$)
    'strUsers$(i%) = Split(strUsers$(i%), "%@世")(0)
    On Error Resume Next
    Debug.Print strUsers$(i%)
    ListView1.ListItems.Add , , strUsers$(1)
     ListView1.ListItems(i%).ListSubItems.Add , , strUsers$(2)
     ListView1.ListItems(i%).ListSubItems.Add , , strUsers$(3)
    ListView1.ListItems(i%).ListSubItems.Add , , strUsers$(4)
    ListView1.ListItems(i%).ListSubItems.Add , , strUsers$(5)
    Next
    End Sub

  15. #15
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,349

    Re: [RESOLVED] split string help only few extracting

    Worked for me
    Code:
    Private Sub SplitString(ByVal AString As String, ByVal Delimiters As String, ByRef AResult() As String)
    Dim t As String 'temp. String
    Dim p As String 'Primary Delimiter
    Dim r As String 'remaining Delimiters
    Dim i As Long
        p = Left$(Delimiters, 1)
        r = Mid$(Delimiters, 2)
        For i = 1 To Len(r)
            'replace all remaining delimiters with the primary delimiter
            AString = Replace(AString, Mid$(r, i, 1), p)
        Next
        Do
            'trim down consecutive delimiters until there is only one left
            t = Replace(AString, p & p, p)
            If Len(t) = Len(AString) Then
                Exit Do
            Else
                AString = t
            End If
        Loop
        'If first character is a delimiter, trim it off
        'That way first Member of Result-Array is not an empty member
        If Left$(AString, 1) = p Then AString = Mid$(AString, 2)
        'If last character is a delimiter, trim it off
        'That way last Member of Result-Array is not an empty member
        If Right$(AString, 1) = p Then AString = Left$(AString, Len(AString) - 1)
        AResult = Split(AString, p)
    End Sub
    
    Private Sub CommandButton1_Click()
    Dim PacketArray() As String
    Dim Data As String
    Dim SearchString As String
    Dim i As Long
        
        Data = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        SplitString Data, "%@", PacketArray
        SearchString = "GetHost#"
        
        i = LBound(PacketArray)
        On Error Resume Next  'In the unlikely case you run out of bounds during the last iteration
        Do While i <= UBound(PacketArray)
            If PacketArray(i) = SearchString Then
                ListView1.ListItems.Add , , PacketArray(i + 1)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = PacketArray(i + 2)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(2) = PacketArray(i + 3)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(3) = PacketArray(i + 4)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(4) = PacketArray(i + 5)
                i = i + 6
            Else
                i = i + 1
            End If
        Loop
    End Sub
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  16. #16

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: [RESOLVED] split string help only few extracting

    Quote Originally Posted by Zvoni View Post
    Worked for me
    Code:
    Private Sub SplitString(ByVal AString As String, ByVal Delimiters As String, ByRef AResult() As String)
    Dim t As String 'temp. String
    Dim p As String 'Primary Delimiter
    Dim r As String 'remaining Delimiters
    Dim i As Long
        p = Left$(Delimiters, 1)
        r = Mid$(Delimiters, 2)
        For i = 1 To Len(r)
            'replace all remaining delimiters with the primary delimiter
            AString = Replace(AString, Mid$(r, i, 1), p)
        Next
        Do
            'trim down consecutive delimiters until there is only one left
            t = Replace(AString, p & p, p)
            If Len(t) = Len(AString) Then
                Exit Do
            Else
                AString = t
            End If
        Loop
        'If first character is a delimiter, trim it off
        'That way first Member of Result-Array is not an empty member
        If Left$(AString, 1) = p Then AString = Mid$(AString, 2)
        'If last character is a delimiter, trim it off
        'That way last Member of Result-Array is not an empty member
        If Right$(AString, 1) = p Then AString = Left$(AString, Len(AString) - 1)
        AResult = Split(AString, p)
    End Sub
    
    Private Sub CommandButton1_Click()
    Dim PacketArray() As String
    Dim Data As String
    Dim SearchString As String
    Dim i As Long
        
        Data = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        SplitString Data, "%@", PacketArray
        SearchString = "GetHost#"
        
        i = LBound(PacketArray)
        On Error Resume Next  'In the unlikely case you run out of bounds during the last iteration
        Do While i <= UBound(PacketArray)
            If PacketArray(i) = SearchString Then
                ListView1.ListItems.Add , , PacketArray(i + 1)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = PacketArray(i + 2)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(2) = PacketArray(i + 3)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(3) = PacketArray(i + 4)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(4) = PacketArray(i + 5)
                i = i + 6
            Else
                i = i + 1
            End If
        Loop
    End Sub
    Will try it when I get home.
    The code looks nice and neat,my code looks messy

  17. #17

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: [RESOLVED] split string help only few extracting

    Quote Originally Posted by Zvoni View Post
    Worked for me
    Code:
    Private Sub SplitString(ByVal AString As String, ByVal Delimiters As String, ByRef AResult() As String)
    Dim t As String 'temp. String
    Dim p As String 'Primary Delimiter
    Dim r As String 'remaining Delimiters
    Dim i As Long
        p = Left$(Delimiters, 1)
        r = Mid$(Delimiters, 2)
        For i = 1 To Len(r)
            'replace all remaining delimiters with the primary delimiter
            AString = Replace(AString, Mid$(r, i, 1), p)
        Next
        Do
            'trim down consecutive delimiters until there is only one left
            t = Replace(AString, p & p, p)
            If Len(t) = Len(AString) Then
                Exit Do
            Else
                AString = t
            End If
        Loop
        'If first character is a delimiter, trim it off
        'That way first Member of Result-Array is not an empty member
        If Left$(AString, 1) = p Then AString = Mid$(AString, 2)
        'If last character is a delimiter, trim it off
        'That way last Member of Result-Array is not an empty member
        If Right$(AString, 1) = p Then AString = Left$(AString, Len(AString) - 1)
        AResult = Split(AString, p)
    End Sub
    
    Private Sub CommandButton1_Click()
    Dim PacketArray() As String
    Dim Data As String
    Dim SearchString As String
    Dim i As Long
        
        Data = "@dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetHost#@%@tamina%@men of war%@Text1.Text%@0/8%@e2d1ef98-61d9@dE%GetHost#@%@james%@men of war%@Text1.Text%@6/8%@e2d1ef98-61d9"
        SplitString Data, "%@", PacketArray
        SearchString = "GetHost#"
        
        i = LBound(PacketArray)
        On Error Resume Next  'In the unlikely case you run out of bounds during the last iteration
        Do While i <= UBound(PacketArray)
            If PacketArray(i) = SearchString Then
                ListView1.ListItems.Add , , PacketArray(i + 1)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = PacketArray(i + 2)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(2) = PacketArray(i + 3)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(3) = PacketArray(i + 4)
                ListView1.ListItems(ListView1.ListItems.Count).SubItems(4) = PacketArray(i + 5)
                i = i + 6
            Else
                i = i + 1
            End If
        Loop
    End Sub
    nice one bro

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