Read Text File line by line

Hello,

I am creating a text file with Activity “Write Text File” in one sequence of my project.
I want to read this file line by line in another sequence of the same project.
I am using Activity “Read Text File” first and then I use activity “For Each” to access one Item at a time.
My file after "Read Text File " looks like the below screenshot.
A window labeled "Watch" displays a sequence of alphanumeric strings in a list format, with buttons for "Copy to Clipboard" and "Cancel" at the bottom. (Captioned by AI)
And “For Each” gives me one character only but I need the complete line.
How can I achieve this?
Thank you.

Hi @parnalmahavir.patni

In For each give like below

fileContent.Split(Environment.NewLine.ToCharArray()

Regards,

1 Like

we can do it directly

Assign activity:
arrLines | DataType: String Array =
File.ReadAllLines("FullFilePath")

UPD1 - enhanced explanation added

Then we can loop over arrLines within a for each activity

when looping over a string the looped item is the character.

Flattening the string array we can do:
strFlatten = String.Join(Environment.NewLine, arrLines)

1 Like

Hi @parnalmahavir.patni

Check the below syntax:

stringArray = inputString.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

stringArray is of DataType Array(System.String).

Hope it helps!!

1 Like

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