How to Read line by line and search for specific word

I have took my text files in an assign activities of string array type .e filecollection = Directory.GetFiles(filePath,fileToSearch)

Then i read the file using Read text File activity. Like this: fileCollection(0).toString

Now i want to read the text file line by line and search for the keyword “DTC Local Code” then beside this keyword i have some numbers i want to extract that numbers.

And there are so many files so i kept all these acrivities in a for each loop.

And also there is a more space in between DTC local code and those numbers but it is in same line

Pls help me

Hi @Tabbu

You can try with Regex expression.
Can you able to send the sample text file

Regards
Gokul

Hi

Can you give us an example of how the sentence will look like
@Tabbu

@Tabbu

As @Gokul001 said it will be done using Regex, but if you can provide some sample text you want to search into

Thanks


This is the text file.

Also i have used regex but i m not getting the output

Hi @Tabbu

  • Read the text file and save it in Output variable - “ReadText”
    Try with this Regex Expression

Your Variable = System.Text.RegularExpression.regex.Match(ReadText,"").ToString

Regards
Gokul


Already used this expression but its not working.
This str_codefile is the output variable of Read Text file activity

Can you share the sample Text file in the Notepad @Tabbu

Actually i forget my password so not able to login through laptop. But the formate is like this only as i show above

This regex is not working → (?<=DTC Local Code.)\d+

Try with this regex expression

Hi

Hope the below steps would help you resolve this

  1. Use a BUILD DATATABLE activity with a single column named code of type string and get the output as dt

  2. Now use a CLEAR DATATABLE activity and mention datatable as dt

  3. Then use a assign activity like this

arr_filepaths = Directory.GetFiles(“your folderpath”)

  1. Use a FOR EACH activity where pass arr_filepaths as input and change the type argument as string

  2. Inside the loop use a READ TEXT FILE activity and pass item as input and get the output as strinput of type string

  3. Now use a Assign activity like this

Stroutput = System.Text.RegularExpressions.Regex.Match(Strinput.ToString.ToUpper.Trim, “(?<=CODE)\d+”)).ToString.Trim

  1. Now use a add DATAROW activity where in ARRAYROW mention like {stroutput.ToString} and in DATATABLE mention as dt

Hope this would help you

Cheers @Tabbu

Hi @Tabbu

Check this condition works

system.text.RegularExpressions.Regex.Match(str_CodeFile.toUpper,"(?<=CODE).*").ToString.trim

Thanks,


Still empty output

Hi @Tabbu

Please check the text file contains data before you apply regex

Thanks

Please try the below regex :
strDTCcode = Regex.Match(strText ,"(?<=DTC\s*Local\s*Code\s*)[\d]+").Value

Not working still getting empty output

Please print str_codefile & regex matched variable using write line activity (instead of message box) in output panel and share the screenshot.

Only thing is you need to share the sample Text file @Tabbu