本文介绍了如何从字符串列表中提取数组索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想知道如何提取某些数组索引并传入变量。我希望能够提取某些数组索引(即第一行和第二行的字符串),如下例所示: 字符串Array []名为: 93935NAA2 93935NAB0 93935QAB3 93935QAF4 939355AB9 仅读取第一行。 预期输出: 93935NAA2 从第二行开始读到列表末尾。 预期产出: 93935NAB0 93935QAB3 93935QAF4 939355AB9 b $ b 任何指南都将不胜感激。非常感谢解决方案 看看这个: http:// www .tutorialspoint.com / csharp / csharp_arrays.htm [ ^ ] 我想我明白你的意思,但如果没有,你需要更详细地解释一下。 private T [] Extract< T>(IEnumerable< T> input, int startIndex, 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:93935NAA293935NAB093935QAB393935QAF4939355AB9Read first line only.Expected output:93935NAA2Starts reading from second line till the end of the list.Expected output:93935NAB093935QAB393935QAF4939355AB9Any 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); 这篇关于如何从字符串列表中提取数组索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 05:33