Select second item in string


#1

Hi All

I am trying to data scrape a text file. What i do is read the text file into a string then search a string in a line and display that line if found. That works fine. What i struggling with is i want to find an string in a line and if true look for another string in the very next line, if true, message box both values.

Any ideas


#2

One way

StringArray arr= FileReadAllLines(sample.txt)
Line=1

While line <= arr.length -1
{
If(arr(line).Contains(“xyz”) AND arr(line+1).Contains("xyz))

MessageBox— arr(line) + arr(line+1)

Line = Line +1
}


#3

Do I do this via the “Invoke power shell”?


#4

Okay i have managed to build it but i get the following:

Main has thrown an exception

Message: Index was out of range. Check that the collection has values and the index is less than the size of the collection.

Source: If

Exception Type: IndexOutOfRangeException


#5

Line=0

While line <= arr.length -2


#6

Perfect. Thx it worked.


#7

Okay after some testing this did not work. If there is more than 2 lines in the text file it gets stuck in the loop.


#8

Share the screenshot of your workflow, are you incrementing the counter and is the counter outside if condition (inside while).

Use writeline to see which line robot is working on.


#9

Okay it was my mistake. I had the increment in the IF and not the While. Here is the working flow.