Option Explicit Const Def_Value As String = "010203050612131516172223242526278"Dim ResultArr() As String Dim i As Integer, j As IntegerPrivate Sub Form_Load() Call GetValue(Def_Value) End SubPublic Function GetValue(ByVal sValue As String) ReDim ResultArr(0) As String
Dim s As String Dim tmpArrIndex As Integer tmpArrIndex = IIf(Len(sValue) Mod 2 > 0, Len(sValue) Mod 2 + 1, Len(sValue) Mod 2)
If tmpArrIndex > 0 Then _ sValue = Left$(sValue, Len(sValue) - 1)
For i = 1 To Len(sValue) - 1 Step 2 Dim tmp1, tmp2 tmp1 = Val(Mid(Mid(sValue, i), 1, 2)) + 1 tmp2 = Val(Mid(Mid(sValue, i), 3, 2))
If tmp1 = tmp2 Then ReDim Preserve ResultArr(0 To UBound(ResultArr) + 1) As String ResultArr(UBound(ResultArr) - 1) = Mid(Mid(sValue, i), 1, 2) ResultArr(UBound(ResultArr)) = Mid(Mid(sValue, i), 3, 2) Else On Error Resume Next For j = 0 To UBound(ResultArr) s = s + ResultArr(j) Next Debug.Print s Debug.Print ""
ReDim ResultArr(0) As String s = "" End If
DoEvents Next End Function
我给你一个简单的! Private Sub GetValue(ByVal strV As String, arrValue() As String) Dim strT1 As String, strT2 As String Dim strTmpValue As String Dim lLen As Long Dim I As Long
lLen = Len(strV)
For I = 1 To lLen Step 2 strT2 = Mid(strV, I, 2) Me.List2.AddItem strT2 If strT1 <> "" Then If Val(strT2) - Val(strT1) = 1 Then strTmpValue = strTmpValue & strT2 Else strTmpValue = strTmpValue & "|" & strT2 End If strT1 = strT2 Else strTmpValue = strT2 strT1 = strT2 End If Next I
arrValue = Split(strTmpValue, "|") End Sub
笔误!语句:Me.List2.AddItem strT2 应删除!
sub GetArrey(strtemp as string) dim i as integer dim tstr as string for i=1 to len(strtemp) step 6 tstr=mid(strtemp,i,6) if len(tstr)=6 then if val(right(tstr,2))-val(mid(tstr,3,2)=1 AND val(mid(tstr,3,2))-val(left(tstr,2))=1 then debug.print tstr end if next i end sub
sub GetArrey(strtemp as string) dim i as integer dim tstr as string for i=1 to len(strtemp) tstr=mid(strtemp,i,6) if len(tstr)=6 then if val(right(tstr,2))-val(mid(tstr,3,2)=1 AND val(mid(tstr,3,2))-val(left(tstr,2))=1 then debug.print tstr end if next i end sub
wfnuser(夏雪)兄,数据长度不是固定的!
Dim str As String Dim aa() As String Dim lngTmp As Long Dim lngTemp As Long Dim strString As String Dim str1 As String Dim i As Long str = "01020312130105" lngTmp = CLng(Left(str, 2)) str1 = Left(str, 2) Do Until False str = Right(str, Len(str) - 2) If Len(str) < 1 Then Exit Do lngTemp = CLng(Left(str, 2)) If lngTmp > lngTemp Then str1 = str1 & "-" lngTmp = lngTemp str1 = str1 & Left(str, 2) Else lngTmp = lngTemp str1 = str1 & Left(str, 2) End If Loop aa = Split(str1, "-")
Rick110AAA(海牛) and NotReady(No) 的代码可行 ------------------谢谢 其实这是我们大学时期的数据结构中一个很具有代表意义的算法。 现在怀念读书啊。 --------- 结帖
string 必要参数。字符串表达式,从中返回字符。如果 string 包含 Null,将返回 Null。
start 必要参数。为 Long。string 中被取出部分的字符位置。如果 start 超过 string 的字符数,Mid 返回零长度字符串 ("")。
length 可选参数;为 Variant (Long)。要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到尾端的所有字符。
说明欲知 string 的字符数,可用 Len 函数。注意 MidB 函数作用于字符串中包含的字节数据。因此其参数指定的是字节数,而不是字符数。
MyString = "Mid Function Demo" 建立一个字符串。
FirstWord = Mid(MyString, 1, 3) ' 返回 "Mid"。
LastWord = Mid(MyString, 14, 4) ' 返回 "Demo"。
MidWords = Mid(MyString, 5) ' 返回 "Funcion Demo"。
那要通过比较才知道啊.可是这个算法是????
Const Def_Value As String = "010203050612131516172223242526278"Dim ResultArr() As String
Dim i As Integer, j As IntegerPrivate Sub Form_Load()
Call GetValue(Def_Value)
End SubPublic Function GetValue(ByVal sValue As String)
ReDim ResultArr(0) As String
Dim s As String
Dim tmpArrIndex As Integer
tmpArrIndex = IIf(Len(sValue) Mod 2 > 0, Len(sValue) Mod 2 + 1, Len(sValue) Mod 2)
If tmpArrIndex > 0 Then _
sValue = Left$(sValue, Len(sValue) - 1)
For i = 1 To Len(sValue) - 1 Step 2
Dim tmp1, tmp2
tmp1 = Val(Mid(Mid(sValue, i), 1, 2)) + 1
tmp2 = Val(Mid(Mid(sValue, i), 3, 2))
If tmp1 = tmp2 Then
ReDim Preserve ResultArr(0 To UBound(ResultArr) + 1) As String
ResultArr(UBound(ResultArr) - 1) = Mid(Mid(sValue, i), 1, 2)
ResultArr(UBound(ResultArr)) = Mid(Mid(sValue, i), 3, 2)
Else
On Error Resume Next
For j = 0 To UBound(ResultArr)
s = s + ResultArr(j)
Next
Debug.Print s
Debug.Print ""
ReDim ResultArr(0) As String
s = ""
End If
DoEvents
Next
End Function
Private Sub GetValue(ByVal strV As String, arrValue() As String)
Dim strT1 As String, strT2 As String
Dim strTmpValue As String
Dim lLen As Long
Dim I As Long
lLen = Len(strV)
For I = 1 To lLen Step 2
strT2 = Mid(strV, I, 2)
Me.List2.AddItem strT2
If strT1 <> "" Then
If Val(strT2) - Val(strT1) = 1 Then
strTmpValue = strTmpValue & strT2
Else
strTmpValue = strTmpValue & "|" & strT2
End If
strT1 = strT2
Else
strTmpValue = strT2
strT1 = strT2
End If
Next I
arrValue = Split(strTmpValue, "|")
End Sub
dim i as integer
dim tstr as string
for i=1 to len(strtemp) step 6 tstr=mid(strtemp,i,6)
if len(tstr)=6 then
if val(right(tstr,2))-val(mid(tstr,3,2)=1 AND val(mid(tstr,3,2))-val(left(tstr,2))=1 then
debug.print tstr
end if
next i
end sub
dim i as integer
dim tstr as string
for i=1 to len(strtemp)
tstr=mid(strtemp,i,6)
if len(tstr)=6 then
if val(right(tstr,2))-val(mid(tstr,3,2)=1 AND val(mid(tstr,3,2))-val(left(tstr,2))=1 then
debug.print tstr
end if
next i
end sub
Dim aa() As String
Dim lngTmp As Long
Dim lngTemp As Long
Dim strString As String
Dim str1 As String
Dim i As Long
str = "01020312130105"
lngTmp = CLng(Left(str, 2))
str1 = Left(str, 2)
Do Until False
str = Right(str, Len(str) - 2)
If Len(str) < 1 Then Exit Do
lngTemp = CLng(Left(str, 2))
If lngTmp > lngTemp Then
str1 = str1 & "-"
lngTmp = lngTemp
str1 = str1 & Left(str, 2)
Else
lngTmp = lngTemp
str1 = str1 & Left(str, 2)
End If
Loop
aa = Split(str1, "-")
------------------谢谢
其实这是我们大学时期的数据结构中一个很具有代表意义的算法。
现在怀念读书啊。
---------
结帖