程序代码:
Private Sub Command1_Click() Dim strArr() As String Dim strArr2() As String Dim StrLine As String StrLine = "C出现次数:12" & vbCrLf & _ "Z出现次数:8" & vbCrLf & _ "T出现次数:123" & vbCrLf & _ "D出现次数:10" & vbCrLf & _ "N出现次数:9" Text1.Text = StrLine strArr = Split(StrLine, vbCrLf) lenArr = UBound(strArr) ReDim strArr2(lenArr, 1) For i = 0 To lenArr '再次分割成二维数组 t = Split(strArr(i), ":") strArr2(i, 0) = t(0) strArr2(i, 1) = t(1) Next For i = 0 To lenArr - 1 For j = i To lenArr If (CInt(strArr2(i, 1)) > CInt(strArr2(j, 1))) Then t1 = strArr2(i, 0) t2 = strArr2(i, 1) strArr2(i, 0) = strArr2(j, 0) strArr2(i, 1) = strArr2(j, 1) strArr2(j, 0) = t1 strArr2(j, 1) = t2 End If Next Next StrLine = "" For i = 0 To lenArr '组合字符串 StrLine = StrLine & strArr2(i, 0) & ":" & strArr2(i, 1) & vbCrLf Next Text2.Text = StrLine End Sub
[此贴子已经被作者于2022-3-4 15:05编辑过]