vb.net - 拆分列表框项目[关闭]

问题描述 投票:-1回答:1

我试图拆分列表框的一些元素时遇到问题...

那我在做什么:

  • 我浏览一个包含许多Youtube链接和艺术家/标题的文本文件
  • 此文本文件中的所有行都添加到列表框中(我的图片左侧第一个框)
  • 通过单击“下一步”,我想只获得没有艺术家和标题的链接(在同一行上)

问题是我不知道该怎么做...我已经看过this linkthis one但是无法为我的项目改变它。

我知道YouTube链接是43个字符。

所以我要做的是:

  • 选择我的列表框的每一行,只选择43个第一个字符(链接)
  • 显示我的第二个列表框的每一行上的每个链接。

对不起,如果有语法错误,英语不是我的母语。

vb.net split listbox character
1个回答
0
投票

在线评论

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
© www.soinside.com 2019 - 2024. All rights reserved.