Extract String from Text file


#1

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.

#2

HI @TwinkleTyagi,

Can you provide the sample input and your expected output.

Regards, Arivu :slight_smile:


#3

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


#4

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"


#5

HI @TwinkleTyagi,

Refer this post

Regards, Arivu :slight_smile:


#6

Can you please provide me xaml file.


#7

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)


#8

Hi @TwinkleTyagi,

check the workflow,

ReadTextFile.xaml (7.1 KB)


#9

@TwinkleTyagi Check below file

Between.zip (1.8 KB)


#10

Thank you Manju Nath, it worked.

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