FindAll.vb
''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Linq
Imports GrapeCity.Documents.Word

'' This sample shows how to find all occurrences of a string
'' in a DOCX document (see JsFrameworkExcerpt) using the
'' RangeBase.Find extension method provided by the
'' RangeBaseFindReplaceExtensions class.
Public Class FindAll
    Public Function CreateDocx() As GcWordDocument
        '' The string to find. Note that we use all lowercase,
        '' as we specify the ignore case option in the find call
        Const findPattern = "javascript framework"

        '' Load the document:
        Dim doc = New GcWordDocument()
        doc.Load(Path.Combine("Resources", "WordDocs", "JsFrameworkExcerpt.docx"))

        '' Find all occurrences of the search string, ignoring the case:
        Dim finds = doc.Body.Find(findPattern, New FindOptions(doc) With {.IgnoreCase = True})

        '' Print the number of found occurrences at the top of the document
        doc.Body.Paragraphs.Insert($"Found {finds.Count()} occurrences of '{findPattern}' in the document." + vbCrLf + vbCrLf, InsertLocation.Start)

        '' Done
        Return doc
    End Function
End Class