Reading a text file and extract and store the values in variables

In the text file there are few values which I wish to retrieve. For example in the text file there are values which follows *X1, and so on. I tried to split the contents wish space and stored them in an Array. But challenge I’m facing are -

  1. On Splitting using space, the spaces are also getting stored in array. How to get rid of those?
  2. How to retrieve the values following X1. For example, 00001X123456 and output which I wish to have is 23456.
  3. There are few addresses as well. So when I split with space, the addresses also gets stored in separate indexes in Array. So how to get the whole address in a variable.

Here are the contents of text file -

000TESTFILE_V101 00001*X123456   0000050KGS0000123    002*Y123456   0000060KGS0000456    0003*X178901   0000+025FT00000987      *Z1      XYZ TechSolutions Ltd.  27 XY Street    ABC TUZB5 TX 0

Steps I’ve followed-

  1. Read text tile activity to read the text file contents and saved in output variable - fileContents.
  2. Used the Assign Activity to split and store the text file data -
    strArray = fileContents.Split(" "C)
  3. Tried to print the array contents passing indexes using Log message activity.

Any advise on what will be the best logic to achieve this requirement would be of great help. Thanks in advance.

H! @kaustubh.aras28

you can try with regex

for the X1 it will give two outputs so based on the index you can cal it.
Regex.Matches(reg,“(?<=X1)\d+”)

for the reference you can see the screenshot
image

thanks @Praveen_Mudhiraj . if could you please share the xaml file as well with the given solution would be helpful.

I have made only sample for X1 text

Regex_X1.zip (1.5 KB)

let me know if it is working or not for you

@kaustubh.aras28

Hey You can also refer the below xaml
Main.xaml (10.3 KB)

1 Like

Thanks @Praveen_Mudhiraj was able to make it work using Matches activity. As I have the text in textfile and I’m reading through it.

Would you also help me as well in extracting the 50 from 50KGS as well from the same string.

I was attaching the xaml same for KGS also if you need with regex you can go for that process
Regex_X1.zip (1.6 KB)

if you need to go with matches activity… for the reference I will attach the screenshot ,you can refer it
for the X1 text After 23456

for 50KGs Text to 50

Let me know if working or not
Cheers… @kaustubh.aras28

Thanks @tazunnisa.badavide it worked!

Thanks @Praveen_Mudhiraj It worked! Thanks for the help.

1 Like

@Praveen_Mudhiraj - Would you also please help me with the regular expression to achieve this?

*C106 XYZ TechSolutions Ltd. 27 XY Street ABC TUZB5 TX 0 *B050 ABC ABCSolutions Ltd. 72 XY Street ABC TUZB5 TX 0

I wanted to have the text which is following *C106 i.e (XYZ TechSolutions Ltd. 27 XY Street ABC TUZB5 TX 0). I used this regex

(?<=C106\s).*$

but it takes in text from *B050 as well in output.

Could you please advise?

For getting the upto this (XYZ TechSolutions Ltd. 27 XY Street ABC TUZB5 TX 0).

You can use this… I will attach a screenshot please follow that same way…

@kaustubh.aras28

1 Like

Thanks @Praveen_Mudhiraj . It worked!

1 Like

Cheers…!

@kaustubh.aras28

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.