# Extract String from Text file

**URL:** <https://forum.uipath.com/t/extract-string-from-text-file/33947>\
**Category:** Help\
**Tags:** system, activities\
**Created:** [May 24, 2018, 6:58am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947 "2018-05-24T06:58:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TwinkleTyagi](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@TwinkleTyagi](https://forum.uipath.com/u/TwinkleTyagi)\
**Post date:** [May 24, 2018, 6:58am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/1 "2018-05-24T06:58:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [May 24, 2018, 7:15am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/2 "2018-05-24T07:15:44Z")

</div>

HI @TwinkleTyagi,

Can you provide the sample input and your expected output.

Regards, Arivu 🙂

---

<div class="post-metadata">

**Author:** ![sarathi125](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sarathi125/32/519448_2.png) [@sarathi125](https://forum.uipath.com/u/sarathi125)\
**Post date:** [May 24, 2018, 7:26am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/3 "2018-05-24T07:26:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TwinkleTyagi](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@TwinkleTyagi](https://forum.uipath.com/u/TwinkleTyagi)\
**Post date:** [May 24, 2018, 7:33am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/4 "2018-05-24T07:33:09Z")

</div>

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"

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [May 24, 2018, 7:38am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/5 "2018-05-24T07:38:40Z")

</div>

HI @TwinkleTyagi,

Refer this post

> [@Read file Txt](https://forum.uipath.com/t/read-file-txt/28242/4):
>
> Hi @sebasmc07, Use Matches activity First Value: Use Matches activity Properties Input : YourInputString Pattern : ((?\<=DE FACTURA:).\*(?=FECHA:)) Result: iEnumResult -\>IEnumberable after that use assign activity to get the data strFirst=iEnumResult (0).ToString() Second Value: Use Matches activity Properties Input : YourInputString Pattern : ((?\<=Para:).\*(?=Enviar)) Result: iEnumResult -\>IEnumberable after that use assign activity to get the data strSecond=iEnumResult (0).ToStri…

Regards, Arivu 🙂

---

<div class="post-metadata">

**Author:** ![TwinkleTyagi](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@TwinkleTyagi](https://forum.uipath.com/u/TwinkleTyagi)\
**Post date:** [May 24, 2018, 7:39am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/6 "2018-05-24T07:39:22Z")

</div>

Can you please provide me xaml file.

---

<div class="post-metadata">

**Author:** ![Prakshi\_Tyagi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/prakshi_tyagi/32/1796_2.png) [@Prakshi\_Tyagi](https://forum.uipath.com/u/Prakshi_Tyagi)\
**Post date:** [May 24, 2018, 7:52am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/7 "2018-05-24T07:52:27Z")

</div>

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](https://global.discourse-cdn.com/uipath/original/3X/7/d/7dd0bf3d12dadac0ad1e17f7b9db4609bb766a89.xaml) (6.2 KB)

---

<div class="post-metadata">

**Author:** ![sarathi125](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sarathi125/32/519448_2.png) [@sarathi125](https://forum.uipath.com/u/sarathi125)\
**Post date:** [May 24, 2018, 7:54am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/8 "2018-05-24T07:54:41Z")

</div>

Hi @TwinkleTyagi,

check the workflow,

[ReadTextFile.xaml](https://global.discourse-cdn.com/uipath/original/3X/7/7/7776a66f2b7fb96e753c1ea68013d67632c96223.xaml) (7.1 KB)

---

<div class="post-metadata">

**Author:** ![Manjuts90](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manjuts90/32/176617_2.png) [@Manjuts90](https://forum.uipath.com/u/Manjuts90)\
**Post date:** [May 24, 2018, 7:57am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/9 "2018-05-24T07:57:40Z")

</div>

@TwinkleTyagi Check below file

[Between.zip](https://global.discourse-cdn.com/uipath/original/3X/b/a/ba3cdcb46ba1e3b4028d121399b404e69da90b09.zip) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![TwinkleTyagi](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@TwinkleTyagi](https://forum.uipath.com/u/TwinkleTyagi)\
**Post date:** [May 24, 2018, 9:10am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/10 "2018-05-24T09:10:02Z")

</div>

Thank you Manju Nath, it worked.

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

---

<div class="post-metadata">

**Author:** ![krp](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krp](https://forum.uipath.com/u/krp)\
**Post date:** [November 3, 2018, 11:58am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/11 "2018-11-03T11:58:37Z")

</div>

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 1[Error Message.xlsx](https://global.discourse-cdn.com/uipath/original/3X/1/9/19843cbd4290742dc44aa90efad2257249f25360.xlsx) (94.4 KB)

---

<div class="post-metadata">

**Author:** ![ndivya](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@ndivya](https://forum.uipath.com/u/ndivya)\
**Post date:** [November 20, 2018, 10:51am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/12 "2018-11-20T10:51:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PrankurJoshi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/prankurjoshi/32/37212_2.png) [@PrankurJoshi](https://forum.uipath.com/u/PrankurJoshi)\
**Post date:** [November 20, 2018, 11:00am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/13 "2018-11-20T11:00:54Z")

</div>

Hi @ndivya

Try this

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

```

Thanks,  
Prankur

---

<div class="post-metadata">

**Author:** ![ndivya](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@ndivya](https://forum.uipath.com/u/ndivya)\
**Post date:** [November 20, 2018, 11:52am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/14 "2018-11-20T11:52:35Z")

</div>

Thanks,It’s working…

---

<div class="post-metadata">

**Author:** ![jeevan302](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jeevan302/32/52898_2.png) [@jeevan302](https://forum.uipath.com/u/jeevan302)\
**Post date:** [January 4, 2019, 9:48am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/15 "2019-01-04T09:48:53Z")

</div>

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

010 Silicon hoses shiny glossy blue L  
bend 90 deg reducer 1.5 to 1.25  
inches  
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

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [January 4, 2019, 9:50am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/16 "2019-01-04T09:50:55Z")

</div>

Hi @jeevan302,

> [@jeevan302](#):
>
> 010 Silicon hoses shiny glossy blue L  
> bend 90 deg reducer 1.5 to 1.25  
> inches  
> 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

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

Regards,  
Arivu

---

<div class="post-metadata">

**Author:** ![jeevan302](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jeevan302/32/52898_2.png) [@jeevan302](https://forum.uipath.com/u/jeevan302)\
**Post date:** [January 4, 2019, 10:12am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/17 "2019-01-04T10:12:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeevan302](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jeevan302/32/52898_2.png) [@jeevan302](https://forum.uipath.com/u/jeevan302)\
**Post date:** [January 4, 2019, 10:13am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/18 "2019-01-04T10:13:01Z")

</div>

i want data extract in sequential from but use by loop

---

<div class="post-metadata">

**Author:** ![Karthick\_Settu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/karthick_settu/32/41725_2.png) [@Karthick\_Settu](https://forum.uipath.com/u/Karthick_Settu)\
**Post date:** [January 4, 2019, 11:22am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/19 "2019-01-04T11:22:03Z")

</div>

Check this.  
[String Split Loop.zip](https://global.discourse-cdn.com/uipath/original/3X/2/f/2f6344aad055e82552f9d3d451a117f4e283f7d7.zip) (2.8 KB)

---

<div class="post-metadata">

**Author:** ![MarkC1500](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@MarkC1500](https://forum.uipath.com/u/MarkC1500)\
**Post date:** [February 5, 2019, 5:07am UTC](https://forum.uipath.com/t/extract-string-from-text-file/33947/20 "2019-02-05T05:07:27Z")

</div>

@Manjuts90

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](mailto: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

[Next page](https://forum.uipath.com/t/extract-string-from-text-file/33947.md?page=2)
