交叉索引引用 [英] Cross Index Referencing
问题描述
对不起,如果标题令人困惑,我不确定我应该如何标注这个,我试过。
Sorry if the title is confusing, I'm not exacting sure how I should label this, I tried.
我正在编写一个程序来做一些交叉索引搜索,该程序使用Visual Studio 2010以C#编写。
I'm writing a program to do some cross index searching, the program is written in C# using Visual Studio 2010.
我有一个包含3列的表:类别
,类型
和项目
。该表从excel电子表格中读取并存储在某种数据结构中(稍后将解释)。以下是该表的简短示例。
I have a table with 3 columns: Category
, Type
, and Item
. The table is read in from a excel spreadsheet and stored in some kind of data structure (will explain this later). Below is a short example of the table.
| CATEGORY | TYPE | ITEM | <<header row
| categoryA | typeA | itemA | <<first entry
| categoryA | typeB | N/A |
| categoryA | typeC | itemB |
| categoryA | typeD | N/A |
我将读取两个用户输入字符串,我希望程序确定它们是否匹配。 [假设用户输入没有错字,我已经写了一个函数来处理这个并且正常化两个字符串]
I will be reading two user input strings, and I want the program determine whether they are a match. [Assuming user input has no typo, I have written a function to handle this and normalize both strings]
确定两个字符串是否匹配的逻辑是这样的:
The logic of determine whether two strings are a match is like this:
1)如果一个字符串是 CATEGORY
,每个 TYPE
和 ITEM
具有相同的 CATEGORY
是一场比赛。
1) If a string is a CATEGORY
, every TYPE
and ITEM
that has the same CATEGORY
is a match.
2)如果字符串是 TYPE
或 ITEM
,则只有同一行中的其他数据是匹配
2) If a string is a TYPE
or ITEM
, only other data in the same row is a match
这里有一些例子,字符串a和b是两个输入字符串,match是一个布尔值:
Here are some examples, string a and b are two input strings and match is a boolean value:
1) a = "categoryA", b = "typeA", match = true
2) a = "categoryA", b = "itemB", match = true
3) a = "typeC", b = "itemB", match = true
4) a = "typeC", b = "itemA", match = false
5) a = "itemA", b = "itemB", match = false
如果这不是足够清楚。
所以我的整体问题是: t是用于存储excel电子表格数据的最合适的数据结构,我将如何进行搜索/比较与此数据结构匹配?
So my overall question is: what is the most suitable data structure to store the data from the excel spreadsheet, and how would I do search/compare match with this data structure?
尽管使用字典< string,string>
,所以我可以在字典中搜索字符串a,并获得匹配字符串的列表并进行比较,但是这样我将有一个巨大的字典和多个
I though of using a Dictionary<string, string>
, so I can search string a in the dictionary and get a list of match strings and compare, but this way I will have a huge dictionary and multiple same key, which will not work.
任何建议/帮助都不胜感激。
Any suggestion/help is appreciated.
推荐答案
我会考虑使用 DataTable 来自 System.Data
命名空间,适用于存储在表格数据中。什么可能会使您更有吸引力,可以通过 DataView 类 RowFilter 属性。
I would think about using DataTable from System.Data
namespace which is suitable for storing in memory tabular data. What may make it more attractive to you is a possibility to query it with SQL like query via DataView class RowFilter property.
一些伪代码:
DataTable excelTable = new DataTable();
//a method that reads Excel doc and injects data into DataTable
PopulateFromExcel(excelTable);
DataView dv = new DataView(excelTable);
dv.RowFilter = "a = 'categoryA' AND b= 'typeA'";
var match = dv.Count > 0;
这篇关于交叉索引引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!