2013-08-06 44 views
0

[可能重複] How to customize sort order of strings安排串

對於一個據稱訂購該列表同樣的問題排序順序:

[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 

...在此列表:

[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 

假設我忽略了小於100的數字部分 - 即刪除另外兩個:

[email protected] 
[email protected] 
[email protected] 

這可能嗎?我試過下面的代碼,但我不知道如何自定義小於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() 

回答

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 
+0

是的,但輸出爲null.is有一輪? – user2625447

+1

@ user2625447我非常懷疑它是空的。 –