Skip to main content

Scripting - Find Text Right of a Keyword

Article # 3037097 - Page views: 125


Find Text Right of a Keyword


To find free text in the vicinity of a keyword, the combination of a Format Locator and script can be helpful:

Create a Format Locator and let it search for the keyword, e.g., "customer name" together with several variations to cope with OCR errors, e.g., "customer", "name:".

Create a Script Locator with following script, then change the name of the Input Locator as appropriate:

Private Sub SL_TextToTheRight_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, _
                                                 ByVal pLocator As CASCADELib.CscXDocField)

   Dim pWord As CscXDocWord
   Dim pWordLine As CscXDocTextLine
   Dim i As Integer

   Dim InputLocator As CscXDocField
   Set InputLocator = pXDoc.Locators.ItemByName("FL_CustomerName")

If InputLocator.Alternatives.Count = 0 Then Exit Sub

   Dim BestAlternative As CscXDocFieldAlternative
   Set BestAlternative = InputLocator.Alternatives.ItemByIndex(0)

   If BestAlternative.Words.Count = 0 Then Exit Sub

   ' get the last word of the result
   Set pWord = BestAlternative.Words(BestAlternative.Words.Count - 1)
   ' get text line which contains the word
   Set pWordLine = pXDoc.TextLines(pWord.LineIndex)

   ' create an alternative

   ' loop over line and collect all words right of the keyword
   For i = pWord.IndexInTextLine + 1 To pWordLine.Words.Count - 1

      pLocator.Alternatives(0).Words.Append pWordLine.Words(i)

End Sub

Level of Complexity 



Applies to  

Product Version Build Environment Hardware
KTM 6.3, 6.4 All All None



  • Was this article helpful?