Arrays 在Visual Basic中存储文本文件中的记录

Arrays 在Visual Basic中存储文本文件中的记录,arrays,vb.net,visual-studio-2010,visual-studio,sorting,Arrays,Vb.net,Visual Studio 2010,Visual Studio,Sorting,我无法从文本文件中提取记录并将其分离到数组中 所有记录均采用以下格式: --------------------------- CITATION 01 OF 99 ------------------------- Authors: Oliver, Ron Oliver, Helen Title: Information Access and Retrieval with Hypermedia Information Systems. / by Oliver, Ron; Oli

我无法从文本文件中提取记录并将其分离到数组中

所有记录均采用以下格式:

  --------------------------- CITATION   01 OF   99 -------------------------
Authors:  Oliver, Ron
Oliver, Helen
Title:  Information Access and Retrieval with Hypermedia Information Systems. /
 by Oliver, Ron; Oliver, Helen
Pub.Date:  1996
Document no.:  EJ520272
FOUND IN:  British Journal of Educational Technology; v27 n1 p33-44 Jan 1996
Abstract:  Describes an investigation of the search strategies employed by
 novice users of an interactive information system. A class of 12-year-old
 students was instructed in use of an electronic encyclopedia, which they used
 as an information source for projects and to complete skills tests. Students
 employed inefficient search strategies and had difficulty creating search
 requests for information-related problems. (Author/JKP)
Pub.Type:  Research/technical(143); Journal article(080)
Language:  English
RIE/CIJE issue:  CIJJUL96
If not avail. in your library or through ILL, for sale from:  UMI
Minor Identifiers:  Electronic Media
Major Descriptors:  Hypermedia
Information Retrieval
Online Searching
Optical Data Disks
Search Strategies
Minor Descriptors:  Access to Information
Elementary Education
Encyclopedias
Information Sources
Problems
ISSN:  0007-1013
  --------------------------- CITATION   02 OF   99 -------------------------
Authors:  Kimmel, Stacey
Title:  Robot-Generated Databases on the World Wide Web. / by Kimmel, Stacey
Pub.Date:  1996
Document no.:  EJ520165
FOUND IN:  Database; v19 n1 p40-43,46-49 Feb-Mar 1996
Abstract:  Provides an overview of robots that retrieve World Wide Web documents
 and index data and then store it in a database. Nine robot-generated databases
 are described, including record content, services, search features, and sample
 search results; and sidebars discuss the controversy about Web robots and other
 resource discovery tools. (LRW)
Pub.Type:  Descriptive(141); Journal article(080)
Language:  English
RIE/CIJE issue:  CIJJUL96
If not avail. in your library or through ILL, for sale from:  UMI
Major Identifiers:  World Wide Web
Minor Identifiers:  Examples
Major Descriptors:  Databases
Information Retrieval
Online Searching
Robotics
Minor Descriptors:  Comparative Analysis
Indexing
Problems
Search Strategies
ISSN:  0162-4105

And so on....
我只需要以下信息:作者、标题、在中找到的内容以及文本文件中每条记录的摘要。你到底是怎么做的

我的代码:

Public Class Form1

    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click

        Dim fd As New OpenFileDialog()
        fd.Title = "Please select a txt file"
        fd.InitialDirectory = Application.StartupPath & "\inc"
        fd.Filter = "Text Documents (*.txt)|*.txt"
        fd.Multiselect = False
        fd.RestoreDirectory = True
        Dim strFileName As String

        If (fd.ShowDialog() = DialogResult.OK) Then
            strFileName = fd.FileName
            Dim sr As System.IO.StreamReader = System.IO.File.OpenText(strFileName)


            Dim recs As String = sr.ReadToEnd
            ''Dim rec() As String = recs.Split(" ")

            sr.Close()

            txtAbstract.Text = recs(0)

        End If
    End Sub

End Class
我正在使用Microsoft Visual Studio 2010 Express。
提前谢谢。

不要做sr.ReadToEnd。逐行读,这样就容易了


使用LINQ和列表框,您可以获得所需的一切:

ListBox1.DataSource = (From line In IO.File.ReadAllLines(strFileName)
                        Where(line.StartsWith("Authors") OrElse _
                              line.StartsWith("Title") OrElse _
                              line.StartsWith("FOUND IN") OrElse _
                              line.StartsWith("Abstract"))
                       Select line).ToList
这假设数据在样本中跨越多行,实际上是文件中的一行

如果事实上它们是独立的行,那么像这样的东西应该可以工作:

    Dim lines As New List(Of String)
    Dim continueadd As Boolean = False
    Dim sr As New IO.StreamReader(strFileName)
    While Not sr.EndOfStream
        Dim line = sr.ReadLine
        If line.StartsWith("Authors") OrElse _
            line.StartsWith("Title") OrElse _
            line.StartsWith("FOUND IN") OrElse _
            line.StartsWith("Abstract") Then
            continueadd = True
            lines.Add(line)
        ElseIf Not line.Contains(":  ") AndAlso continueadd Then
            lines.Add(line)
        ElseIf line.Contains(":  ") Then
            continueadd = False
        End If
    End While
    ListBox1.DataSource = lines
    Dim lines As New List(Of String)
    Dim continueadd As Boolean = False
    Dim sr As New IO.StreamReader(strFileName)
    While Not sr.EndOfStream
        Dim line = sr.ReadLine
        If line.StartsWith("Authors") OrElse _
            line.StartsWith("Title") OrElse _
            line.StartsWith("FOUND IN") OrElse _
            line.StartsWith("Abstract") Then
            continueadd = True
            lines.Add(line)
        ElseIf Not line.Contains(":  ") AndAlso continueadd Then
            lines.Add(line)
        ElseIf line.Contains(":  ") Then
            continueadd = False
        End If
    End While
    ListBox1.DataSource = lines