如何从字符串列表中提取数组索引? [英] how to extract array index from string list?

查看:81
本文介绍了如何从字符串列表中提取数组索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何提取某些数组索引并传入变量。我希望能够提取某些数组索引(即第一行和第二行的字符串),如下例所示:



字符串Array []名为:

93935NAA2

93935NAB0

93935QAB3

93935QAF4

939355AB9



仅读取第一行。

预期输出:

93935NAA2



从第二行开始读到列表末尾。

预期产出:

93935NAB0

93935QAB3

93935QAF4

939355AB9 < br $> b $ b



任何指南都将不胜感激。非常感谢

解决方案

看看这个: http:// www .tutorialspoint.com / csharp / csharp_arrays.htm [ ^ ]


我想我明白你的意思,但如果没有,你需要更详细地解释一下。

  private  T [] Extract< T>(IEnumerable< T> input, int  startIndex,< span class =code-keyword> int  length = -1)
{
return input.Skip(startIndex)。 Take(length > = 0 ?length:input.Count() - startIndex)。ToArray() ;
}



并测试它:

  string  [] names = {  93935NAA2  93935NAB0  93935QAB3  93935QAF4   939355AB9}; 
string [] one =提取(名称, 0 1 );
string [] some = Extract(names, 1 );


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

解决方案

Check this out: http://www.tutorialspoint.com/csharp/csharp_arrays.htm[^]


I think I see what you mean, but If not, you will need to explain in much better detail.

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:

string[] names = { "93935NAA2", "93935NAB0", "93935QAB3", "93935QAF4", "939355AB9" };
string[] one = Extract(names, 0, 1);
string[] some = Extract(names, 1);


这篇关于如何从字符串列表中提取数组索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆