Read string from a text file and convert to an array

I want to read a string from a text file and such as “24+35” and write the result of this mathematical expression into another text file. How can I convert this string to an array and perform the mathematical operation on the required numbers?

1 Like

Hi
Welcome to uipath community
usually to convert a text to string array
we do like
out_str_array = yourtextvariable.Split(Environment.NewLine.ToArray())
where out_str_array is a variable of type string array

but i would like to know how you want to get the value
kindly provide a sample and elaborate a bit more the requirement pls that could help us go in right direction
Cheers @Mrud2517

1 Like

Hi @Mrud2517

Welcome to the community.

Hope this might be helpful to you.

Scenario 1: Use read text file Activity Read Text File Activity Note: It will return string value.

Scenario 2: Create a variable and declare it as an array of string:

image

Scenario 3:

After getting the value using split Environment.NewLine option spit the value to array
For loop through the array value you can get the each value .

arrStr= strPathvalue.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)

cheers :smiley:

Happy learning :smiley:

1 Like

Hi. So my requirement is to read a mathematical expression from a text file, process it and get the output, and write that very output to another text file. Which function will be apt for this and how should I go about this?

for this we can use READ TEXT FILE activity and get the output as a string output variable named out_text

then

to process this it depends on the process (we need some more details on it)
i hope you were asking for this (not sure)

we do like
out_str_array = yourtextvariable.Split(Environment.NewLine.ToArray())
where out_str_array is a variable of type string array

for this we can use write text file activity

Cheers @Mrud2517

So by process it I mean I need to get the answer for my mathematical expression

Hi @Mrud2517

Maybe you can share your xaml to address the issue promptly.

cheers :smiley:

Happy learning :smiley:

1 Like

Main.xaml (5.6 KB)

So for you guys to understand my task better, I have uploaded the screenshots of the files. The bot has to read the first file, calculate the answer and then write the answer to another text file. My Xaml file is not the entire workflow of the task yet as I was checking if the bot is able to log the characters separately in a for loop. Thanks for all the help till now :slight_smile: am new to this community and just started learning.