Reading text file

Is there any way to fetch the line with a key value, for eg in the below line
“local parameter and identifier is Snapdragon” — I need to fetch the entire line using the word Snapdragon which is the key value, each time that key value can vary and there are close to 100 lines in text file. Any way to retrieve the entire line using the key value?

Try this regex pattern

1 Like

Regex cannot be used here as I am not sure of the type of sentence it could be, it could even be a sentence comprising of number and special signs, so i cannot create a regex pattern for each sentence

@shreyaank In the Text that you have are there any Constant Keywords present always ? So that we can use it as a Reference and Extract the Required Data

No i dont have a constant keyword

@shreyaank Ok . Is your Key Value Known before or is it dynamic ?

Key value is known. i get it by reading from a file, it is a list of key values, but it can change in each line, it wont be the same

@shreyaank Can you Explain the process in detail , If the Key value is the only way to extract data, then you might need to use the Solution provided by @Samir by replacing the Constant SnapDragon with your Dynamic Key value each time in a For Loop by Looping through the keys you have in a List.

i can give you a sample of my lines:

z1 = WorksheetFunction.CountIf(Sheets(“Data”).Range(“e” & y), “" & “RETN” & "”)
key value: RETN

z3 = WorksheetFunction.CountIf(Sheets(“Data”).Range(“e” & y), “" & “RFB” & "”)
key value:RFB

z9 = WorksheetFunction.CountIf(Sheets(“Data”).Range(“e” & y), “" & “NONREF & CASH DISBURSEMENT” & "”)

so using those key values, i need to retrieve the entire line.