帮我整理相结合及放大器;在列表上的过滤帮我、放大器、表上

2023-09-06 23:44:44 作者:一纸荒凉。

我有一个类:

public class MyObject
{
public string Code;
public string FullName;
}

我有MYOBJECT对象的列表:

I have a List of Myobject objects:

Code FullName
"ABC" "The abc company"
"BBC" "The bbc company"
"CPA" "The cpa company"

我的要求:一个匹配的条件是code或含有真实姓名输入字。随着匹配的记录,我会在排序前code和真实姓名后。

My requirement: a matched condition is a Code or FullName contains input word. With matched records, I will sort on Code before and FullName later.

例如:

当用户输入一个字符串:BC,返回一个列表:

When user input a string: "bc", return a list:

Code FullName
"ABC" "The abc company"
"BBC" "The bbc company"

当用户输入一个字符串:啪的一声,返回此列表(请注意,PA是code部分,所以它首先显示)

When user input a string: "pa", return this list (note that "PA" is part of the Code, so it is displayed first):

Code FullName
"CPA" "The cpa company"
"ABC" "The abc company"
"BBC" "The bbc company"

说明:在排序时,code场比全名字段更优先。因为,所有的记录都包含字符串啪,但与codeCPA只记录包含啪的一声,所以它必须是以上。

Explain: When sorting, the Code field is more Priority than FullName field. Because, all of records contains the string "pa" but only the record with Code "CPA" contain "pa", so it must be above.

PS:我使用的是.NET 2.0 / C#2.0。字符串比较筛选不区分大小写。

PS: I'm using .NET 2.0/C# 2.0. String compare in filtering is not case-sensitive.

推荐答案

我要做到以下几点:

创建一个整数数组具有相同长度的企业阵列 在遍历所有的公司 测试,看看该公司code开头的用户输入,如果是的话,加1000至int数组当前的索引。 测试,看看该公司code包含了用户的输入,如果是的话,加100到int数组在当前指数 测试,看看公司全称包含了用户的输入,如果是的话,加10到int数组当前的索引。 (添加额外的测试,在我的字符串搜索系统,我结束了有7截然不同的匹配) 使用int数组作为键排序的公司阵 返回前N个结果,所述排序后的数组,或全部效果,或具有键大于0的所有结果。