Get certain line numbers from string

I used a get text and I have a string that contains 20+ lines.
Lets say I wants to get line 5 from this string.

What kind of sequence would I have?

1 Like

It can either be split by “.” or By new line .

1 Like

@dvn If the Splitting of String doesn’t work by the regular method, you can use this :
strArray = System.Text.RegularExpressions.Regex.Split(str,"\n").Take(5).ToArray

2 Likes

please provide sample input and expected output. @dvn

Thanks!

1 Like

Hi @dvn

You can do the string manipulation.See this link for your reference.

cheers :smiley:

Happy learning :smiley:

2 Likes

Lets say the input came out as 6 lines like this:
Alice : 1234
Jason : 2413
Mark : 2257
Cassy :1111
Brad : 1090
Greg : 7575

I only want the 4th line in this case so my output would be:
Cassy :1111

@dvn If you just want the 4th line, then try this :
str = System.Text.RegularExpressions.Regex.Split(str,"\n")(3)

4 Likes

I tried you example it is working great.
But I also have same condition with some different specification. Can you please help me in this.
like- I also have above condition
Lets say the input came out as 6 lines like this:
Alice : 1234
Jason : 2413
Mark : 2257
Cassy :1111
Brad : 1090
Greg : 7575

I only want the 4th line in this case so my output would be:
I have to first search Cassy … that it is appearing or not then if it appearing
then I only want 1111 of cassy in a variable…

please show me a way with Regex how I can manage all things
Thanks for help- Inn advance

Main Specifications-

  1. I don’t know where is Cassy appearing. No line position known so can’t pass index (3)
  2. I have to first search Cassy … that it is appearing or not then if it appearing
    then I only want 1111 of Cassy in a variable…

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