Extract String from Text file

I want to extract specific string from a text file.
I have tried 2 methods but struck on same point:

  1. I have read the text file and saved data in form of list of string type.
  2. I have read text file and saved data in a single string variable using ReadLine.
    My problem is how to get index of specific words from string or list so that I can use substring method to get substring containing data between specific words.
    I am using IndexOf to get index of that word but everytime I am getting 0 as result.
    please help.
1 Like

HI @TwinkleTyagi,

Can you provide the sample input and your expected output.

Regards, Arivu :slight_smile:

Hi @TwinkleTyagi,

Try something like this in Invoke Code activity,

Dim St As String = “string pulled from the text file using reader which has key : text I want to keep - end of my string”
Dim pFrom As Integer = St.IndexOf("key : ") + "key : “.Length
Dim pTo As Integer = St.LastIndexOf(” - ")
Dim result As String = St.Substring(pFrom, pTo - pFrom)

Note: “key :” and " -" are the two strings of the string’s starting and end which we need to search and get.
we can return the result to the workflow and can use it

Like if a text file contains text -
"Quick brown

fox jumps right

over the little

lazy dog."

And I want to get the text between words “fox” and “lazy”.

Then the output should be -

"fox jumps right

over the little"

HI @TwinkleTyagi,

Refer this post

Regards, Arivu :slight_smile:

Can you please provide me xaml file.

Hello @TwinkleTyagi

Attaching a sample .xaml file for your reference. I have used invoke code activity which accepts “from” and “to” strings as input arguments. You can change them and check as per your need.

Let me know if this helps
GetTextBetweenStrings.xaml (6.2 KB)

1 Like

Hi @TwinkleTyagi,

check the workflow,

ReadTextFile.xaml (7.1 KB)

@TwinkleTyagi Check below file

Between.zip (1.8 KB)

1 Like

Thank you Manju Nath, it worked.

and thank you everyone for your valuable information, I learned a lot.

Prakshi - I tried to follow your example of finding text between strings using an invoke code approach. While I was able to add the code, I am getting an error message as follows and oddly the “invoke code” activity is red not black like the other activities in the list. I am attaching some screen shots as well. Thank you so much for your help! Kim

Here is the error message:
No compiled code to run
Error BC30451 ‘strPDF’ is not declared. It may be inaccessible due to its protection level. At line 1Error Message.xlsx (94.4 KB)

How can we extract a string that is repeated in text file and count of repeated text?

Eg: This is UIpath Forum.For beginners Forum is useful.
Forum got repeated twice so count is 2.
How can we get 2 value using Uipath

Hi @ndivya

Try this

int Count = Regex.Matches(myText, "Forum", RegexOptions.Multiline Or RegexOptions.IgnoreCase).Count 



Thanks,It’s working…

1 Like

Hi Arive
i follow your Instraction to extract data between the string, if we extract the data from some line in string

010 Silicon hoses shiny glossy blue L
bend 90 deg reducer 1.5 to 1.25
25.00 piece
Requested delivery period from 1 9/06/2018 til l 22/06/2018020 Silicon hoses shiny glossy blue L
bend 90 deg reducer 2.5 to 2 inch
20.00 piece
Requested delivery period from 1 9/06/2018 til l 22/06/2018
030 Silicon hoses shiny glossy blue
straight reducer 4 to 2 inches
10.00 piece
Requested delivery period from 1 9/06/2018 til l 22/06/2018
040 Silicon hoses shiny glossy blue
straight reducer 4 to 2.5 inches
10.00 piece
Request 7000543257 Date: 19/06/2018

actually i want the extract data from 010 to 020 and i wantt to use in loop can you guide me
how to extract data between this string and used in loop

Hi @jeevan302,

so this is your input correct can you tell me the output how you want?


i want data

like between
from 010 to 020
and i want use in loop …data automatic extract from like
1.data 010 to 020
2.data 020 to 030
3.data 020 to 040
4.data 040 t0 end

but i want to used in loop

i want data extract in sequential from but use by loop

Check this.
String Split Loop.zip (2.8 KB)

1 Like


Hi. I am using the Between,zip. Can someone help me elaborate on it a bit.

I need to extract text from the following text file. The first bit of text i need to get is between the first instance of “Email” and first instance of “Buyers Name”.

I have this working with your sequence. But what do I do if i need to split between second instance of “Email” and Second Instance of “Buyers Name”??

Also, I have this string as one of my outputs "hi@gmail.com John Smith". I need to split this into two but keep the name and not the email. I am using this buyersname(1).Split({"@"},stringsplitoptions.None) but just returning the email.

Thank you