Option Explicit
Sub TEST()
MsgBox N_L("235-237,238", "-", ",") & vbLf & vbLf _
& N_L("235~237;238;236~240;260~261;25", "~", ";")
End Sub
Function N_L(數字串$, 連續符$, 間隔符$) As String
Dim A, Z, V, i&, X&, Mi&, Ma&, N&, T$
Set Z = CreateObject("Scripting.Dictionary")
If InStr(數字串, 間隔符) = 0 Or Val(數字串) = 0 Then N_L = "": Exit Function
On Error GoTo Rear
For Each A In Split(Replace(數字串, 連續符, "-"), 間隔符)
A = A & "-" & A: A = Split(A, "-")(0) & "-" & Split(A, "-")(1)
For i = 0 To Abs(Evaluate(A))
V = Val(A) + i
If N = 0 Then Mi = V: Ma = Mi: N = 1
Z(V) = 1
If V < Mi Then Mi = V Else: If V > Ma Then Ma = V
Next
Next
For i = Mi To Ma
If Z(i) <> "" And X = 0 Then T = T & 間隔符 & i: X = 1
If Z(i + 1) = "" And X = 1 Then X = 0: GoTo i01
If Z(i + 1) = "" And X > 1 Then T = T & 連續符 & i: X = 0
If Z(i) <> "" Then X = X + 1
i01: Next
Rear: If Err.Number = 0 Then N_L = Mid(T, 2) Else: N_L = ""
Set Z = Nothing
End Function作者: Andy2483 時間: 2023-6-12 16:34