How to extract last 8 lines and first 4 lines from a notepad

How to extract last 8 lines and first 4 lines from a notepad.

I have a notepad with several lines. I need to copy the last 8 lines from the notepad and then extract the first 4 lines from the 8 lines.

How can I achieve this

@Krithi1

  1. read the data into string variable
  2. Now use assign with requiredstring = String.Join(Environment.Newline,strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Skip(strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Count-8).Take(4))

cheers

1 Like

Thank you soo much, that works.

Can you also tell me how to read line by line now?

I need to apply some split functions on each line, after reading line by line

1 Like

@Krithi1

if you need line by line…its basically the array or list you need

so just remove string.join from above and you would get array of 4 lines

ArrayVar = strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Skip(strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Count-8).Take(4).ToArray

cheers

@Anil_G

Instead of array, how can I directly get line 1, line 2, line 3 and line 4?

@Krithi1

If you loop the array inside loop you will get each line

Cheers

@Anil_G - The below expression is not working as expected. I believe “RemoveEmptyEntries” might be causing some issue. What does it mean by when we say “RemoveEmptyEntries” though? If it’s removing the empty lines in between the lines, I don’t want to do that. Can you please update the expression? I tried a couple of things and it didn’t work

requiredstring = String.Join(Environment.Newline,strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Skip(strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Count-8).Take(4))

@Krithi1

If you dont want that then use None in place of it

Cheers