0

[可能重复] 如何自定义字符串的排序顺序

关于订购此列表的同一问题:

bufallo@2000
lice@20
cell@1
rat@150
cow@10000

...进入此列表:

cow@10000
bufallo@2000
rat@150
lice@20
cell@1

假设我要忽略小于 100 的数字部分 - 也就是说,删除其他两个:

cow@10000
bufallo@2000
rat@150

这可能吗?我已经尝试了下面的代码,但我不知道如何自定义小于 100 的数字部分,从而删除其余部分。

Dim number As Int32 = Int32.MinValue
Dim orderedLines = From line In TextBox1.Lines
                   Let parts = line.Split("@"c)
                   Let numericPart = parts.Last()
                   Let success = Int32.TryParse(numericPart, number)
                   Select LineInfo = New With {line, number}
                   Order By LineInfo.number Descending
                   Select LineInfo.line
' if you want to reassign it to the TextBox:
TextBox1.Lines = orderedLines.ToArray()
4

1 回答 1

1

我的 VB LINQ 经验很少,但这是您想要的吗?

Dim orderedLines = From line In TextBox1.Lines
                   Let parts = line.Split("@"c)
                   Let numericPart = parts.Last()
                   Let success = Int32.TryParse(numericPart, number)
                   Select LineInfo = New With {line, number}
                   Where number >= 100      ' something like this?
                   Order By LineInfo.number Descending
                   Select LineInfo.line
于 2013-08-06T16:05:38.953 回答