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
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
requiredstring = String.Join(Environment.Newline,strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Skip(strvar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Count-8).Take(4))cheers
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
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
Instead of array, how can I directly get line 1, line 2, line 3 and line 4?
@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))