能解决的自己一个一个解决一下,也算抛砖引玉:
‘带字母数字排除序:
- Function SortStr(str As String) As String '
- Dim sr, ar(0 To 10000), r, c, i, j, k '按数字的最大值,自行修改ar的数组上限
- Dim s As String, ss As String, t
- sr = Split(str, ",")
- For t = 0 To UBound(sr)
- k = ExtNum(sr(t))
- If ar(k) = "" Then ar(k) = sr(t) Else ar(k) = ar(k) & "," & sr(t)
- Next
- For j = 0 To UBound(ar)
- If ar(j) <> "" Then
- If s = "" Then s = ar(j) Else s = s & "," & ar(j)
- End If
- Next
- SortStr = s
- End Function
- Sub tt()
- Dim str As String
- 'str = "A9,A29,A30,A32,A10,A19,A3,A7,A8,A15,A18,A20,A28"
- str = "3A,7A,8A,9A,10A,15A,18A,19A,20A,28A,29A,30A,32A"
- Debug.Print SortStr(str)
- End Sub
复制代码
' 全角标点符号转半角标点符号
- Public Function q2b(t)
- Dim arr, BRR, i&
- arr = Split(", \ . ! ? ; : ' ' "" "" [ ] { } ( )")
- BRR = Split(", 、 。 ! ? ; : ‘ ’ “ ” 【 】 { } ( )")
- For i = LBound(BRR) To UBound(BRR)
- 't = Replace(t, ARR(i), BRR(i))
- t = Replace(t, BRR(i), arr(i))
- Next i
- q2b = t
- End Function
- Sub ttt()
- Dim str As String
- str = "QW,ER、TY。UI!OP?AS;DF:GH‘JK’L“ZX”CV【BN】M{00}1(99)"
- Debug.Print q2b(str)
- End Sub
复制代码
结合 ExtNum 提取数字自定义函数使用
- Function ExtNum(str As Variant) As Integer '
- Dim reg, sr, h As Integer, mh
- Set reg = CreateObject("vbscript.regexp")
- reg.Global = True
- reg.Pattern = "[0-9,.]+"
- Set sr = reg.Execute(str)
- For Each mh In sr
- h = mh
- Next
- ExtNum = h
- End Function
- Sub tttt()
- Dim str As String
- str = "44AH"
- Debug.Print ExtNum(str)
- End Sub
复制代码
一个小问题,用到的知识点还不少
再次感谢各位老师! |