【问题标题】:Skip to the string and take other items跳到字符串并拿走其他物品
【发布时间】:2022-01-26 22:03:45
【问题描述】:

我有文件夹段列表"c:\","user","temp","subfolder1","subfolder2" 我想找到"temp" item 之后的所有项目并加入他们。我已经使用两种方法解决了它:首先我找到一个“temp”索引,然后使用另一种 Linq 方法。

也许有一个 Skip 方法不仅接受索引而且接受名称? 像这样的

directories.Skip("Temp").Skip(1).Take(1000)

我当前的代码

var findIndex = directories.FindIndex(f=>f.ToLower()=="temp");
if (findIndex != -1)
{
    filePath = string.Join(@"\", directories.Skip(findIndex).Skip(1).Take(1000));
}

【问题讨论】:

    标签: c# linq


    【解决方案1】:

    你可以使用SkipWhile:

    directories.SkipWhile(x => x != "Temp").Skip(1).Take(1000)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 2017-12-25
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多