Find Text Right of a Keyword
17797
QAID # 17797 Published
Question / Problem:
Find Text Right of a Keyword
Answer / Solution:
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 pLocator.Alternatives.Create() ' 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) Next End Sub
Applies To:
Product | Version | Category |
---|---|---|
AXPRO | 4.0 | Script |
AXPRO | 4.5 | Script |
AXPRO | 5.0 | Script |
AXPRO | 5.5 | Script |