Results 1 to 4 of 4

Thread: Splitting a large string while adding it to a listview?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2021
    Posts
    4

    Splitting a large string while adding it to a listview?

    Hello, I am looking for guidance on how to Split up this large string, while also adding it to my listview.

    *@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST& %SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND# !THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$

    I am looking to add every single 'FIRST' as the listview item, 'SECOND' as the subitem, and 'THIRD' as the last subitem.

    At the moment, I am only able to add the first set into my listview.
    I have a feeling I need a loop, as well as remove part of the string once it has been added to the listview, but I am quite new to VB and have tried and tried, though unsuccessful.
    If you are someone who could help resolve this for me id be really greatfull for your help.

    Code:
    Dim stringdata as string = "*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$"
    
    Dim ida As Integer = stringdata.IndexOf("@")
    Dim fda As String = stringdata.Substring(ida + 1, stringdata.IndexOf("&", id + 1) - id - 1)
    Dim idb As Integer = stringdata.IndexOf("%")
    Dim fdb As String = stringdata.Substring(idb + 1, stringdata.IndexOf("#", id + 1) - id - 1)
    Dim idc As Integer = stringdata.IndexOf("!")
    Dim fdc As String = stringdata.Substring(idc + 1, stringdata.IndexOf("$", id + 1) - id - 1)
    
    ListView1.Items.Add(New ListViewItem({fda, fdb, fdc}))
    This is all I have been able to pull from that string
    Name:  123.png
Views: 171
Size:  1.3 KB
    Attached Images Attached Images  
    Last edited by VBnoobie1; Jun 17th, 2021 at 08:58 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,130

    Re: Splitting a large string while adding it to a listview?

    How about you provide a FULL and CLEAR explanation of the problem, which would include a description of EXACTLY how you want to split the text. We should have to work out what you're trying to do from code that doesn't do it. We should have to work out what you're trying to do at all because you already know so you should just tell us.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2021
    Posts
    4

    Re: Splitting a large string while adding it to a listview?

    My post seemed pretty clear.. I am unable to strip the string to add each set, which consists of *@FIRST&%SECOND#!THIRD$ , to my list. With the script I wrote, it only adds the first set. I think I need a loop as well.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2021
    Posts
    4

    Re: Splitting a large string while adding it to a listview?

    I figured it out. Didnt need the world known sass by jmcilhinney.

    Incase others are wondering,
    Code:
    Dim StringData as string = "*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$*@FIRST&%SECOND#!THIRD$"
    Dim SplitString() As String = StringData.Split("^")
                        Dim SplitLength As Integer = 0
                        Dim Spl As String = "^"
                        For Each Spl In returndata
                            SplitLength += 1
                        Next
                        Dim Lvn As Integer = 1
                        For i As Integer = 0 To SplitLength - Lvn Step Lvn
                            Dim ida As Integer = SplitString(i).IndexOf("@")
                            Dim fda As String = SplitString(i).Substring(ida + 1, SplitString(i).IndexOf("&", ida + 1) - ida - 1)
                            Dim idb As Integer = SplitString(i).IndexOf("%")
                            Dim fdb As String = SplitString(i).Substring(idb + 1, SplitString(i).IndexOf("#", idb + 1) - idb - 1)
                            Dim idc As Integer = SplitString(i).IndexOf("!")
                            Dim fdc As String = SplitString(i).Substring(idc + 1, SplitString(i).IndexOf("$", idc + 1) - idc - 1)
                            Listview1.Items.Add(New ListViewItem(New String() {fda, fdb, fdc}))
                        Next

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