如何在按钮单击时导入ListView时从txt文件中删除某些单词?
目前我有3列,每列用“|”分隔
Dim Path As String = OpenFileDialog1.FileName
Dim AllItems As String
Try
AllItems = My.Computer.FileSystem.ReadAllText(Path)
Dim ItemLines As New TextBox
ItemLines.Text = AllItems
For Each line As String In ItemLines.Lines
Dim List1() As String = line.Split("|")
Dim ItemName As String = List1(0)
Dim SubItem1 As String = List2(1)
Dim SubItem2 As String = List3(2)
Dim Item As New ListViewItem(ItemName)
Item.SubItems.Add(SubItem1)
Item.SubItems.Add(SubItem2)
Item.SubItems.Add(SubItem2)
ListView1.Items.AddRange(New ListViewItem() {Item})
文本文件包含以下字词: 你好:500 |世界:20 |年龄:30 |
我想删除单词
你好:世界:年龄:
并且只显示 500 20 30 在ListView中为其后面的每一列
答案 0 :(得分:0)
如果您的数据格式为
AAAAA: ### | AAAAA: ### | AAAAA: ### |
你已经通过管道分裂了,因为你在数组中进行迭代,你可以使用{:1}的Substring()
进行IndexOf()
。这将获得每个数组元素的分号后面的数字。
类似的东西:
Imports System
Public Module Module1
Public Sub Main()
Dim line = "Hello: 500 | World: 20 | Age: 30 |"
Dim linePieces = line.Split(new Char() {"|"c}, StringSplitOptions.RemoveEmptyEntries)
For Each piece As String in linePieces
Console.WriteLine(piece.SubString(piece.IndexOf(":") + 1).Trim())
Next
End Sub
End Module
结果:
500
20
30