Read Text from last line to first one

Hello colleagues,
Could you help me with the following issue?
what I want to achieve is to read a text, saved in a variable, from the last line to the first one. I don’t know how to achive it. I saw examples on how to read a text backwards, like this: backwards = “sdrawkcab”.
But I need something more like this:

My name is Jhon,
I am 13 years old,
I am tall,
I have a dog

and make the system read it like:

I have a dog,
I am tall,
I am 13 years old,
My name is Jhon,

Is there a way to achieve this?
Thanks in advance
Andres

Hi @ae.nz.testing
Welcome to UiPath community.

here is the solution:

  1. Read the text into a string variable
  2. Split the text based on myText.Split(Environment.NewLine)
  3. Get the length of the lines
  4. in while loop, use lines length logic to loop through each line and execute the last line first and go backward by using counter logic.
    Attached is the xaml file for your reference. Please let me know if it meets your requirement.

ReadingBackward.xaml (8.0 KB)

1 Like

Hello @ae.nz.testing

Try this method:

image

Step 1: Save your text as String1.
Step 2: Capture each line as an Array of String
Arr_Matches = System.Text.RegularExpressions.Regex.Matches(String1, “.+”).Cast(Of System.Text.RegularExpressions.Match)().Select(Function(a) a.Value).ToArray()

Step 3: Reverse the array’s order
You will need to save this using a new/different Array of String.

Arr_Reversed = arr_Matches.Reverse().ToArray

Step 4: Join Array of String using a new line to separate them.
Join(arr_Reversed, Environment.NewLine)

Cheers

Steve

Thanks! I’ll give it a try and see if it works for me.

Thanks for taking your time to answer me Steven… I’ll see how it works!

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