[英]Enumerated Directories Name Substring GroupBy Issue
I'm trying to make a lookup from a set of enumerated directories using the GroupBy
function. 我正在尝试使用GroupBy
函数从一组枚举目录中进行查找。 I have part of the solution, but can't seem to figure out the rest. 我有解决方案的一部分,但似乎无法弄清楚其余的问题。
The directories are in a format where the letters of Substring(3,6) are used as the main category and Substring(0,2) will be used as a subcategory. 目录采用以下格式:将Substring(3,6)的字母用作主要类别,将Substring(0,2)的字母用作子类别。
IList<string> sliceSteppingList = mainFolder
.EnumerateDirectories("?x??0?0*", SearchOption.TopDirectoryOnly)
.Select(x => x.Name)
.ToList();
This yields part of the solution, where the output is a sorted list and uses the categories like I wanted, but it has the entire folder name as under the groups, which is not what I want. 这产生了解决方案的一部分,其中输出是一个排序列表,并使用我想要的类别,但是它具有整个文件夹名称,就像在组下一样,这不是我想要的。
The folder names are in this format: 文件夹名称采用以下格式:
1x6A0A0 1x6C0C0 3x8A0A0 3x8B0B0 3x8C0C0 5x8A0A0 1x6A0A0SS0 1x6A0A0SS1 1x6A0A0SS2
What I want it a lookup that has a dictionary or lookup something like this 我想要的是具有字典的查找或类似这样的查找
-A0 +1x6 +5x8 -B0 +3x8 -C0 +1x6 +3x8
The part with the SSx
is would be considered a selection after the main and subcategories are chosen, but I'm not sure what to do with that part yet. 选择了主要类别和子类别后,可以将带有SSx
的零件视为一个选择,但是我不确定该零件该怎么做。
From what I understand from your question and sample output, you are looking for a GroupBy
like this: 根据我对问题和示例输出的了解,您正在寻找这样的GroupBy
:
var sliceSteppingList = mainFolder
.EnumerateDirectories("?x??0?0*", SearchOption.TopDirectoryOnly)
.Select(dirInfo => dirInfo.Name)
.GroupBy(dirName => dirName.Substring(3, 4), dirName => dirName.Substring(0, 3))
.OrderBy(group => group.Key);
Here's an example of a way to display the output: 这是显示输出的示例:
foreach (var item in sliceSteppingList)
{
Console.WriteLine($"-{item.Key}");
foreach (var subDir in item)
{
Console.WriteLine($" +{subDir}");
}
}
Output 产量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.