根据关键字词组排序 [英] Sorting according to keyword phrases

查看:128
本文介绍了根据关键字词组排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想对存储在以下数组,列表,数据表中的任何一个中的数据进行排序...

例如,如果我对以下内容进行排序:

1)房子钱钱
2)钱
3)钱屋
4)房子
5)金钱对我们很重要吗?

结果应为:

4)房子
2)钱
3)钱屋
1)房子钱钱
5)金钱对我们很重要吗?

等待您的回应.

谢谢
Kapil

Hello,

I want to sort the data stored in any one of following Array, List, DataTable ...

For example, if I sort the following :

1) house money money
2) money
3) money house
4) house
5) Is money important to us

The result should be :

4) house
2) money
3) money house
1) house money money
5) Is money important to us

Awaiting your response.

Thanks
Kapil

推荐答案

使用linq,它是一个简单的衬里:

Using linq, it''s a simple one liner:

var results = vals.OrderBy(x => x.Split(' ').Count());



鉴于vals是您的字符串数组,即



Given that vals is your string array, i.e.

var vals = new string[]
{
    "house money money",
    "money",
    "money house",
    "house",
    "Is money important to us",
};


您将需要实现自定义 ^ ]
You would need to implement a custom IComparer[^]


这篇关于根据关键字词组排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆