Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to know how I can extract certain array index and pass in variable. I would like to be able to extract certain array index (i.e. string from 1st line and 2nd second line), as shown below in the example:

String Array [ ] called Names:
93935NAA2
93935NAB0
93935QAB3
93935QAF4
939355AB9

Read first line only.
Expected output:
93935NAA2

Starts reading from second line till the end of the list.
Expected output:
93935NAB0
93935QAB3
93935QAF4
939355AB9


Any guide would be appreciated. Many Thanks
Posted

 
Share this answer
 
I think I see what you mean, but If not, you will need to explain in much better detail.
C#
private T[] Extract<T>(IEnumerable<T> input, int startIndex, int length = -1)
    {
    return input.Skip(startIndex).Take(length >= 0 ? length: input.Count() - startIndex).ToArray();
    }

And to test it:
C#
string[] names = { "93935NAA2", "93935NAB0", "93935QAB3", "93935QAF4", "939355AB9" };
string[] one = Extract(names, 0, 1);
string[] some = Extract(names, 1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900