然后以L(i)为下标范围对原字符串进行冒泡排序即可。
这思路里的---“然后以L(i)为下标范围”是?能否具体说明?
哦 这样的
新建一个窗体, 放两个文本筐 放一个按钮 加如下代码
Private Sub Command1_Click()
Dim strTemp As String
Dim strCmp As String
Dim strArr() As String
Dim llCount As Long
strTemp = Text1
strCmp = GetStr(Text1)
ReDim strArr(Len(strCmp)) As String
For llCount = 1 To Len(strCmp)
strArr(llCount) = Mid(strCmp, llCount, 1)
Next
'排序
Text2 = ""
Dim tmp As String
Dim i As Integer, j As Integer
For i = 1 To Len(strCmp)
For j = i + 1 To Len(strCmp)
If strArr(i) > strArr(j) Then
'交换两数
tmp = strArr(i): strArr(i) = strArr(j): strArr(j) = tmp
End If
Next j
Next i
i = 0
For llCount = 1 To Len(strTemp)
If Mid(strTemp, llCount, 1) Like "[^a-z]" Then
i = i + 1
Text2 = Text2 & strArr(i)
Else
Text2 = Text2 & Mid(strTemp, llCount, 1)
End If
Next
End Sub
Private Sub Form_Load()
Text1 = "ccbb1aa4ggff1ee"
Text2 = ""
End Sub
Public Function GetStr(str) As String '自定义函数
Dim TStr, re
TStr = str
Set re = CreateObject("vbscript.regexp") '正则表达式对象
re.Pattern = "[^a-z]" '规则非数字字符
re.Global = True '全局可用性。
TStr = re.Replace(TStr, "")
Set re = Nothing '释放对象
GetStr = TStr
End Function