-1

I'm having an issue while trying to split some elements of my List Box... Preview of my program][1

So what I'm doing :

  • I browse for a text file that contains many Youtube links and artist/title
  • All lines from this textfile are added in a Listbox (1st box left on my picture)
  • By clicking "Next" I want to get only the links without the artist and the titles (that are on the same lines)

Problem is I don't know how to do that... I already saw this link and this one but can't manage to change it for my project.

I know that a YouTube link is 43 characters.

So what I'm trying to do is :

  • pick each line of my listbox and take only the 43 first characters (the link)

  • display each link on each line of my 2nd listbox.

Sorry if there are grammar mistakes, englsih isn't my native language.

Michal
  • 2,078
  • 23
  • 36
Valenz
  • 3
  • 1
  • 1
    My suggestion is to redefine the your data handling: a simple way is to create a class structure, save and load by serializing/deserializing a JSON. So, you'll have all the data ready from the beginning. – Jimi Mar 20 '19 at 23:04
  • @Jimi well thanks but that doesn't solve my problem ^^ I have more than 50 links in this text file. And I have no idea what all that "class structure, save and load by serializing/deserializing a JSON" is... Do you mean edit all links into a json file ? That would be long as hell haha. There should be a solution for my case it's not something impossible but it's just hard for a beginner like me – Valenz Mar 20 '19 at 23:09
  • No, I'ld suggest to build a class structure that can hold the informations you need, parse the strings you have in that file and feed the results to the class structure, then use Newtonsoft.Json to serialize the class structure to a new file. To separate the string you have now, you can Substring the original with something like: `Dim authors As String = line.Substring(line.IndexOf("//", 10)).TrimStart("// ".ToCharArray())` and `Dim url As String = line.Substring(0, line.IndexOf("//", 10)).TrimEnd()`, where `line` is the line of text your read from your file. – Jimi Mar 21 '19 at 00:11

1 Answers1

0

Comments in-line

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'put each item in the list box into an array
    Dim arrList() As String = ListBox1.Items.OfType(Of String).ToArray
    'Trim each item in the array to a length of 43 characters
    Dim arrURL() As String = (From url In arrList
                              Select url.Substring(0, 43)).ToArray
    'Add the array as a Range to the items collection of the second list box
    ListBox2.Items.AddRange(arrURL)
End Sub
Mary
  • 14,926
  • 3
  • 18
  • 27
  • Thanks a lot ! Works perfectly ! How can I change my question as resolved ? (I'm new here) Edit : saw the checkmark button ^^ – Valenz Mar 21 '19 at 09:04