将 .txt 中的文本分离到列表视图中的列中(VB.net mobile)
问题描述:
我想在 VB.net 中将每个文本分成自己的列.
I want to separate each text into their own Column in VB.net.
我如何实现这一目标?
每个主菜用|"分隔.我的代码:
Each entree is seperated with "|" . My Code:
Private Sub MenuItem3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim folder As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
Using sw As StreamWriter = File.AppendText("\My Expenses.txt")
sw.WriteLine(DateTimePicker.Text + Space(1) & "|" & Subject.Text + Space(4) & "|" & Category.Text + Space(5) & "|" & Amount.Text + Space(4) & "|" & Peyment.Text)
sw.Close()
End Using
End Sub
答
目前我没有任何移动应用程序可以进行实验,但我相信这样的事情正是您所追求的:
I do not have any mobile apps to experiment on at this moment, but I believe something like this is what you are after:
Private Sub MenuItem3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Using sw As StreamWriter = File.AppendText("\My Expenses.txt")
For Each item As ListViewItem in ListView1
Dim line As String = Nothing
For Each entry As String in item.SubItems
line.Append(entry & "|")
Next For
sw.WriteLine(line)
Next For
sw.Close()
End Using
End Sub
我可能误解了您要执行的操作,但我认为您是在尝试获取列条目.
I may have misunderstood what you are trying to do, but I think you are trying to get the column entries.
更新:
既然您已将设置保存到文件中,您将如何恢复它们?
Now that you have saved the settings to a file, how would you get them back?
Private Sub PopulateListView()
ListView1.Items.Clear()
Using sr As StreamReader = File.OpenText("\My Expenses.txt")
While (-1 < sr.Peek())
Dim line As String = sr.ReadLine()
Dim item As New ListViewItem(line.Split("|"c))
ListView1.Items.Add(item)
End While
sr.Close()
End Using
End Sub
当然,您的代码可能需要特殊处理,但这涵盖了基本的读写操作.
Naturally, your code may have special handling that is required, but this covers the basic read and write operations.