Read from file and use regex and then write to a new file

I will write the steps.

  1. I am going to read from pdf or textfile. Done
  2. Go throw the “Matches” and use regex code. Done.
  3. Create a fo each loop.
    3.1 Inside the for each loop, i put Append Line.

The thing is that it will always add new lines in my textfile.

The thing that i looking for is that it will overwrite the textfile with the new data.

Where i´m i doing wrong here?

Welcome @Anders_Dahl to uipath community

If you want to overwrite the textfile use write text File activity, don’t use Append Line

Thanks

Hi
Welcome to UiPath community
lets go one by one

use READ PDF or READ PDF with OCR or READ TEXT FILE activity to get the data from the file and save them in a string variable named str_input

use MATCHES activity and pass the string variable str_input as input and mention the expression we want and get the output with a variable of type matches

now pass the output variable from matches as input to FOR EACH activity
–inside the loop use a assign activity like ths
str_output = str_output + item.ToString
where str_output is a variable of type string with default value as string.Empty defined in the variable panel

–now use a WRITE TEXT FILE activity next to this FOR EACH loop and mention the input str_output variable and the file name with its folder path

Cheers @Anders_Dahl

Hi, Inside the loop i have the body

Inside the Body i put Assign ( To= str_output and Value = str_output + item.Tostring)

Thats the only thing i have i that for each loop now.

Do you want me to put the " Write Text File " outside the loop?
The i get this message " Main.xaml: Compiler error(s) encountered processing expression “str_output”.
‘str_output’ is not declared. It may be inaccessible due to its protection level."

And if i put the " Write Text File " inside the loop?
it only writes one time.

make sure that str_output scope is changed to whole sequence in the variable panel
and yes pls put the write text file outside the loop
as this string variable str_output will now hold all the lines we want
and if we have passed this as input to the write text file activity it will overwrite the current file with this str_output value

Cheers @Anders_Dahl

Thanks :slight_smile:
It works fine now!!!
And now i get the answer in one line. Great!
Can i use split to get a coma between the answers?

1 Like

yah ofcourse
arr_lines = Split(strinput,“,”)
where arr_string is a variable of type array of string which will neglect the delimiter , and keep the wordings around it
Cheers @Anders_Dahl

1 Like

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