VB.Net搜索圣经的多个背景

时间:2015-11-04 04:33:44

标签: vb.net vb.net-2010

亲爱的所有dotnet开发者,

我要求你支持我是vb.net的新手。我正在努力开发一个小程序,可以帮助我们当地的教会将圣经中的经文用于我们的星期日学校。我只使用bible.txt文件作为我的源,bible.txt中的上下文格式如下所示:

创世记1:1起初,上帝创造了天地。

创世纪1:2,黑暗笼罩在深处,神的灵正在水面上盘旋。

创世纪1:3神说:“有光,”有光。

创世记1:4上帝看见光是好的,他将光与黑暗隔开。

创世记1:5上帝称光为“白昼”,黑暗称他为“夜”。有傍晚,有早晨 - 第一天。

创世记1:6神说:“在水之间要有一个金库,将水与水分开。”

现在,我如何搜索多节经文?例如,如果我想这样搜索:

有三个文本框,一个用于本书(即创世纪)一个用于章节(即1),一个用于该诗句(即1-2,4-6)

:创世纪1:1-2,4-6

或者如果不可能,我所能做的只是一次一个地搜索,一次一个。是否有可能在richtextbox中添加搜索经文?

例子我先搜索:创世纪1:1,下一个创世记1:2,再创世纪1:4

richtextbox中的结果:

创世记1:1起初,上帝创造了天地。

创世纪1:2,黑暗笼罩在深处,神的灵正在水面上盘旋。

创世记1:4上帝看见光是好的,他将光与黑暗隔开。

谢谢,如果有人可以帮助我。

2 个答案:

答案 0 :(得分:0)

尝试这样的事情



Public Class Form1
    Dim verses As List(Of Verse) = New List(Of Verse)({ _
       New Verse() With {.book = "Genesis", .chapter = 1, .paragraph = 1, .text = "In the beginning God created the heavens and the earth."},
       New Verse() With {.book = "Genesis", .chapter = 1, .paragraph = 2, .text = "and darkness was over the surface of the deep, and the Spirit of God was hovering over the waters."},
       New Verse() With {.book = "Genesis", .chapter = 1, .paragraph = 3, .text = "And God said, ""Let there be light,"" and there was light."},
       New Verse() With {.book = "Genesis", .chapter = 1, .paragraph = 4, .text = "God saw that the light was good, and he separated the light from the darkness."},
       New Verse() With {.book = "Genesis", .chapter = 1, .paragraph = 5, .text = "God called the light ""day,"" and the darkness he called ""night."" And there was evening, and there was morning—the first day."},
       New Verse() With {.book = "Genesis", .chapter = 1, .paragraph = 6, .text = "Let there be a vault between the waters to separate water from water."}
   })

 

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim results As List(Of Verse) = verses.Where(Function(x) x.book = "Genesis").ToList

        Dim light As List(Of Verse) = verses.Where(Function(x) x.text.ToUpper().Contains("LIGHT")).ToList
    End Sub
End Class

Public Class Verse
    Private nBook As String
    Public Property book As String
        Get
            Return nBook
        End Get
        Set(value As String)
            nBook = value
        End Set
    End Property
    Private nChapter As Integer
    Public Property chapter As Integer
        Get
            Return nChapter
        End Get
        Set(value As Integer)
            nChapter = value
        End Set
    End Property
    Private nParagraph As String
    Public Property paragraph As Integer
        Get
            Return nParagraph
        End Get
        Set(value As Integer)
            nParagraph = value
        End Set
    End Property
    Private nText As String
    Public Property text As String
        Get
            Return nText
        End Get
        Set(value As String)
            nText = value
        End Set
    End Property

End Class
​




答案 1 :(得分:0)

Hokay,这是一个非常大的答案。此代码读取圣经文本文件并将其解析为数据表,其中包含书名,章节,经文和诗句文本的列。还有用于保存数据表的代码,如果存在则将其读回。

这应该指向正确的方向。

如果您需要搜索数据表的帮助,请给我发电子邮件,因为解析搜索和显示它的代码需要对表单等进行控制,而且说实话,向您发送整个解决方案的拉链会更容易 - 我怀疑在论坛中不合适。

我使用Visual Studio社区2015版编写了此代码,您可以从Microsoft免费下载。它可能适用于您的2010版本,但我无法确定。

您需要将bible.txt文件拖放到项目中,完成后,需要单击项目中的文件,然后单击“复制到输出目录”中的“复制”文件

    Dim biblePath As String = Application.StartupPath() & "\bible.txt"
    Dim bibleXmlPath As String = Application.StartupPath() & "\bible.xml"
    Dim appPath As String = Application.StartupPath

    Structure bibleVerse
        Dim Book As String
        Dim Chapter As Integer
        Dim VerseNumber As Integer
        Dim VerseText As String
    End Structure

    Dim bible As New DataTable

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        InitializeBibleTable()
    End Sub

    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        If File.Exists(bibleXmlPath) Then
            loadBible(bibleXmlPath, bible)
        Else
            readBibleFromTextFile()
            saveBible(bibleXmlPath, bible)
        End If
        initializeDropDownList()
    End Sub

    Public Sub InitializeBibleTable()
        Dim Book As DataColumn
        Dim Chapter As DataColumn
        Dim VerseNumber As DataColumn
        Dim VerseText As DataColumn
        bible = New DataTable("Bible")
        With bible
            Book = New DataColumn("Book")
            Chapter = New DataColumn("Chapter")
            VerseNumber = New DataColumn("VerseNumber")
            VerseText = New DataColumn("VerseText")
            Book.DataType = System.Type.GetType("System.String")
            Chapter.DataType = System.Type.GetType("System.Int16")
            VerseNumber.DataType = System.Type.GetType("System.Int16")
            VerseText.DataType = System.Type.GetType("System.String")
            .Columns.Add(Book)
            .Columns.Add(Chapter)
            .Columns.Add(VerseNumber)
            .Columns.Add(VerseText)
        End With
    End Sub

     Public Sub loadBible(filename As String, tbl As DataTable)
        Dim tableFile As System.IO.StreamReader
        tableFile = New System.IO.StreamReader(filename)
        tbl.ReadXml(tableFile)
        tableFile.Close()
    End Sub

    Public Sub saveBible(filename As String, tbl As DataTable)
        Dim tableFile As System.IO.StreamWriter
        tableFile = New System.IO.StreamWriter(filename)
        tbl.WriteXml(tableFile, XmlWriteMode.IgnoreSchema)
        tableFile.Close()
    End Sub

    Private Sub readBibleFromTextFile()
        Dim fileReader As System.IO.StreamReader
        fileReader = My.Computer.FileSystem.OpenTextFileReader(biblePath)
        Dim stringReader As String
        While Not fileReader.EndOfStream
            stringReader = fileReader.ReadLine()
            If Not (stringReader = "") Then
                Dim biblerow As DataRow = bible.NewRow
                Dim tempverse As bibleVerse
                tempverse = parseVerse(stringReader)
                biblerow(0) = tempverse.Book
                biblerow(1) = tempverse.Chapter
                biblerow(2) = tempverse.VerseNumber
                biblerow(3) = tempverse.VerseText
                bible.Rows.Add(biblerow)
            End If
        End While
    End Sub

    Function CheckForOKCharacters(ByVal charToCheck As String, validationString As String) As Boolean
        If validationString.Contains(charToCheck) Then
            Return True
        End If
        Return False
    End Function

    Private Function parseVerse(tempVerse As String) As bibleVerse
        Dim parsedVerse As New bibleVerse
        Dim OKCharacters As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,;:!?"
        Dim OKNumbers As String = "1234567890"
        Dim book, verseText As String
        Dim chapter, verseNum As String
        Dim Parsepoint As Integer
        'start parsing book name
        book = ""
        chapter = ""
        verseNum = ""
        verseText = ""
        Parsepoint = 0
        'parse book name
        If IsNumeric(tempVerse(0)) Then
            book = book & tempVerse(0) & " "
            Parsepoint += 2
        End If
        Dim charIsOk As Boolean
        Dim checkChar As String
        Do
            checkChar = tempVerse(Parsepoint)
            charIsOk = CheckForOKCharacters(checkChar, OKCharacters)
            If charIsOk Then
                book = book & checkChar
            End If
            Parsepoint += 1
        Loop Until charIsOk = False
        book = book.Trim()
        'search for chapter number
        Parsepoint -= 1
        Do
            checkChar = tempVerse(Parsepoint)
            charIsOk = CheckForOKCharacters(checkChar, OKNumbers)
            If Not charIsOk Then
                Parsepoint += 1
            End If
        Loop Until charIsOk = True
        'parse chapternumber
        Do
            checkChar = tempVerse(Parsepoint)
            charIsOk = CheckForOKCharacters(checkChar, OKNumbers)
            If charIsOk Then
                chapter = chapter & checkChar
            End If
            Parsepoint += 1
        Loop Until charIsOk = False
        'parse verse number
        Do
            checkChar = tempVerse(Parsepoint)
            charIsOk = CheckForOKCharacters(checkChar, OKNumbers)
            If charIsOk Then
                verseNum = verseNum & checkChar
            End If
            Parsepoint += 1
        Loop Until charIsOk = False
        'search for verse text
        Parsepoint -= 1
        Do
            checkChar = tempVerse(Parsepoint)
            charIsOk = CheckForOKCharacters(checkChar, OKCharacters)
            If Not charIsOk Then
                Parsepoint += 1
            End If
        Loop Until charIsOk = True
        'get verse text from remainder of string
        verseText = tempVerse.Substring(Parsepoint)
        'put parsed values into parsedverse structure and return it
        parsedVerse.Book = book
        parsedVerse.Chapter = CInt(chapter)
        parsedVerse.VerseNumber = CInt(verseNum)
        parsedVerse.VerseText = verseText
        Return parsedVerse
    End Function