Read Invoice values from Text file



Hi All,

I am relatively new to UIPATH. In our company, we create invoice files from AS400. The invoices are in text format. Using the text reading functionalities available in UIPATH, we are able to get the complete text.

But we are struggling to extract relevant data from the text file. What is the best way to distinguish and segregate useful data like date of invoice, company name and Invoice amount etc. We tried to use anchor base but it did not work as expected.

Thanks & Regards


Will you be able to try this? you can use substrings,split to extract additional data

string sCompName = “CompanyName”;
string sAmount = “InvoiceAmount”;

string[] readText = File.ReadAllLines("Invoice.txt");
foreach(item in readText) {
     if(item == sCompName OR item == sAmount)
         // Found it!

Update: made some corrections, You can even read line by line, which I assume is your requirement. Let me know if you have any questions.


Thank you for the speedy reply.
We will try your method to extract values.

Thanks & Regards


Hi Vaidya,

Please let me know where to write the custom code in UIPATH and once we find the relevant keyword like Invoice Amount, how to read the value next to that (The actual invoice amount) ?

Thanks again,



Attached is a simple example.

textfile.xaml (7.6 KB)


Hi Vaidya,

Thanks. We were able to achieve the data extraction with your sample code.

Thanks & Regards


Hi Viadya,

I think I am trying to do the same thing as the person that asked this question. I am trying to pull the text table out of an invoice into an excel file. I have many files all with the same format and would ideally like to go through all of them without opening them. I have just downloaded UIpath so I am still orientating myself.

My item.Contains(“TOTAL”) doesn’t output anything, I am trying to get the total which is to the right of this word. I write putting a “write text file” block after with the “item” variable but I get nothing out.

Ideally I want to get the items in the table and the total at the bottom and then put it into an excel sheet.



Hi @johannpickard

If you use the .Split function you can break it up
For example,

So that will take the 2nd item after you split by the word Total and split again by newline character, which in return will give you the text next to the word Total. And no loop needed.

You can similarly break up the text into an array of line items for which you can process.

Additionally, if you format the text into a CSV format with comma delimiter then you can use Write Text File with .CSV extension, and read it back into a datatable with Read CSV… that is if you choose to.

Hope this helps answer some things :slight_smile:



Hi @ClaytonM,

I have text in this format.
Source Id

How can i extract data (123455) which is in next line after the keyword (Source Id).I didn’t get your previous explanation.Can you eloborate on that?

Thanks in advance.


@sreekanth, Let me try explaining you what @ClaytonM has told,

Say string Str contains the input

Source Id

If you use only the following,
Str.Split({“Source Id"},System.StringSplitOptions.RemoveEmptyEntries)(1) it will give output as,


Because it splits based on the word Source Id where first index i.e 0th index will have a empty/null value and 1st index will have our output mentioned above(italicized).

Again if you make the following operation in that output,
It will return 123455

Because splitting based on newline will give 3 elements while accessing the first one 0th index gives our output(italicized).

Note thus Clayton has used the whole code to get it in a shot.

Dominic :slight_smile:


My string input is below:


Source ID (Name)


Destination ID (Name)


Document Type





May I know what are you getting ?

Dominic :slight_smile:



I have changed datas to array of strings.I am getting the above error


@sreekanth, as we get are accessing only the first index which is nothing but a string then you have to change the type from string array to string. And in error it was clearly mentioned.

Dominic :slight_smile:


When I,m changing 1 dimensional array to string,I,m getting this error.@Dominic


@sreekanth, Your Input has Source ID (Name) in it instead of Source Id . Did you make the changes accordingly?

Dominic :slight_smile:


Hi @sreekanth,

Use Matchs activity

In properties

  • Input-> Str (your input)
  • Pattern-> ((?<=Source Id).*(?=Destination))
  • Output-> IEnumResult (variable data type IEnumerable<Match>)

Source Id output -> IEnumResult(0).ToString()



Hi @sreekanth

Check out the posts here on using Matches pattern to pull out all the values under certain text.



Use screen scraping and assing values to variables.Then build a datatable and add data row using variables.Then you can write the datatable to excel .If you have multiple pdf’s use open application activity and pass your pdf reader.exe in it.



I want to know if for the first pdf the data gets written in the 3rd row . Then what should be done so that the data of 2nd pdf comes in the 4th row.