【问题标题】:Arrange sort order in strings在字符串中排列排序顺序
【发布时间】:2013-08-06 16:02:41
【问题描述】:

[可能重复] How to customize sort order of strings

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

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()

【问题讨论】:

    标签: .net arrays string linq


    【解决方案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
    

    【讨论】:

    • @user2625447 我非常怀疑它是否为空。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多