+1 vote
I need o find specific words inside a field or string. Is that possible in the script..?
asked Nov 18, 2015 in QA Wizard Pro by nico (8,200 points)

1 Answer

+1 vote
Best answer

'This script demonstates how to find specific text in the contents of a text file.

'ReadTextFile reads the content of the given file into a string.
strFileContents = ReadTextFile("%WORKSPACEDIR%\\Seapine Word Search.txt", EncodingAutoDetect)

dumpFileArray = ParseString(strFileContents,"\r") 

'Creates a list of words to search for in the file.
Dim words(4)
words(1) = "Quality"
words(2) = "Assurance"
words(3) = "Seapine"
words(4) = "Software"

'LineCount is equal to the number of elements in the dumpFileArray. 
lineCount = ArraySize(dumpFileArray,1)

For currentWordIndex = 1 To 4 
    wordToSearchFor = words(currentWordIndex)    

    For currentLineIndex = 1 To lineCount         
        
        'Gets the line of text from the array.
        currentLineText = dumpFileArray(currentLineIndex)
        
        'Returns the index where the text begins and prints the corresponding script line number.
        If FindSubStr(currentLineText, wordToSearchFor, 1) > 0 Then 
            PrintLn(wordToSearchFor + " was found in line number " + currentLineIndex)
        End If 
    Next
Next

answered Nov 18, 2015 by nico (8,200 points)
248 questions
262 answers
106 comments
2,047 users