0

我正在尝试做两件事:

我有一个文本文件 ( Books.txt),我正在尝试创建一个应用程序来在ListBox. 文本文件内容如下:

Left Behind,Lahaye,F,7,11.25
A Tale of Two Cities,Dickens,F,100,8.24
Hang a Thousand Trees with Ribbons,Rinaldi,F,30,16.79
Saffy's Angel,McKay,F,20,8.22
Each Little Bird that Sings,Wiles,F,10,7.70
Abiding in Christ,Murray,N,3,12.20
Bible Prophecy,Lahaye and Hindson,N,5,14.95
Captivating,Eldredge,N,12,16
Growing Deep in the Christian Life,Swindoll,N,11,19.95
Prayers that Heal the Heart,Virkler,N,4,12.00
Grow in Grace,Ferguson,N,3,11.95
The Good and Beautiful God,Smith,N,7,11.75
Victory Over the Darkness,Anderson,N,12,16

倒数第三个元素要么F代表小说,要么N代表非小说。我正在尝试将代码写入应用程序查看文本文件的位置,检查元素 3 是否为 anF或 an N,并仅在ListBox.

ListBox的名为lstInventory.

4

1 回答 1

2

您需要将每一行拆分,为一个数组。从那里开始,很容易:

For Each line In IO.File.ReadLines("Books.txt")
    Dim values() As String = line.Split(","c)

    If values(2) = "F" Then
        'Fiction
    Else
        'Nonfiction
    End If
Next
于 2012-07-29T22:17:33.240 回答