'字符和数字组合的字符串排序
Function SortStringAndNumsic(ByVal A As ArrayList) As ArrayList
Dim B As ArrayList = A
Dim I As Long
Dim B_l As ArrayList = New ArrayList
Dim B_r As ArrayList = New ArrayList
For I = 0 To A.Count - 1
Dim Temp As Int16 = FenJieXian(B(I))
B_l.Add(B(I).ToString.Substring(0, Temp))
B_r.Add(B(I).ToString.Substring(Temp))
Next
'先安装左侧字母排序
For I = 0 To B.Count - 2
For J As Int16 = I + 1 To B.Count - 1
If B_l(I) > B_l(J) Then
Dim temp As String = B_l(I)
B_l(I) = B_l(J)
B_l(J) = temp
temp = B_r(I)
B_r(I) = B_r(J)
B_r(J) = temp
temp = B(I)
B(I) = B(J)
B(J) = temp
End If
Next
Next
'再按照右侧数字排序
For I = 0 To B.Count - 2
For J As Int16 = I + 1 To B.Count - 1
If (Val(B_r(I).ToString) > Val(B_r(J).ToString)) And (B_l(I) = B_l(J)) Then '此时需满足两个条件,要保持左侧顺序不变
Dim temp As String = B_r(I)
B_r(I) = B_r(J)
B_r(J) = temp
temp = B_l(I)
B_l(I) = B_l(J)
B_l(J) = temp
temp = B(I)
B(I) = B(J)
B(J) = temp
End If
Next
Next
Return B
End Function
'返回字母和数字组合起来的字符串,字母和数字的字符串分界线,即第一个数字出现的位置
Function FenJieXian(ByVal S As String) As Int16
For i As Int16 = 0 To S.Length - 1
If IsNumeric(S.Substring(i, 1)) = True Then
Return i
Exit For
End If
Next
End Function
Function SortStringAndNumsic(ByVal A As ArrayList) As ArrayList
Dim B As ArrayList = A
Dim I As Long
Dim B_l As ArrayList = New ArrayList
Dim B_r As ArrayList = New ArrayList
For I = 0 To A.Count - 1
Dim Temp As Int16 = FenJieXian(B(I))
B_l.Add(B(I).ToString.Substring(0, Temp))
B_r.Add(B(I).ToString.Substring(Temp))
Next
'先安装左侧字母排序
For I = 0 To B.Count - 2
For J As Int16 = I + 1 To B.Count - 1
If B_l(I) > B_l(J) Then
Dim temp As String = B_l(I)
B_l(I) = B_l(J)
B_l(J) = temp
temp = B_r(I)
B_r(I) = B_r(J)
B_r(J) = temp
temp = B(I)
B(I) = B(J)
B(J) = temp
End If
Next
Next
'再按照右侧数字排序
For I = 0 To B.Count - 2
For J As Int16 = I + 1 To B.Count - 1
If (Val(B_r(I).ToString) > Val(B_r(J).ToString)) And (B_l(I) = B_l(J)) Then '此时需满足两个条件,要保持左侧顺序不变
Dim temp As String = B_r(I)
B_r(I) = B_r(J)
B_r(J) = temp
temp = B_l(I)
B_l(I) = B_l(J)
B_l(J) = temp
temp = B(I)
B(I) = B(J)
B(J) = temp
End If
Next
Next
Return B
End Function
'返回字母和数字组合起来的字符串,字母和数字的字符串分界线,即第一个数字出现的位置
Function FenJieXian(ByVal S As String) As Int16
For i As Int16 = 0 To S.Length - 1
If IsNumeric(S.Substring(i, 1)) = True Then
Return i
Exit For
End If
Next
End Function
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |