Function GetStr(L As Integer)
Dim str, str1, I As Integer, J As Integer, rs(99)
str = "4 4- 5 5- 6 6- 7 7- 8 8- 9 9- 10 10- 11 11- 12 12- 13 13- 1 1- 2 2- 3 3-"
str = (Replace(str, " ", ",")) & ","
For I = 1 To Len(str)
If Mid(str, I, 1) = "," Then
J = J + 1
rs(J) = I
End If
Next I
I = 1
If L > 1 And L <= J Then
GetStr = Mid(str, rs(L - 1) + 1, rs(L) - rs(L - 1) - 1)
ElseIf L = 1 Then
GetStr = Left(str, rs(L) - 1)
ElseIf L > J Then
MsgBox "超出数据范围"
End If
End Function
Function GetStr(L As Integer)
Dim str, str1, I As Integer, J As Integer, rs(99)
str = " 4 4- 5 5- 6 6- 7 7- 8 8- 9 9- 10 10- 11 11- 12 12- 13 13- 1 1- 2 2- 3 3-"
str = (Replace(Trim(str), " ", ","))
''Replace space
MsgBox str
Do Until InStr(1, str, ",,", 1) = 0
str = (Replace(str, ",,", ","))
str = str
Loop
str = str & ","
MsgBox str
''Get "," position
For I = 1 To Len(str)
If Mid(str, I, 1) = "," Then
J = J + 1
rs(J) = I
End If
Next I
I = 1
''Get string
If L > 1 And L <= J Then
GetStr = Mid(str, rs(L - 1) + 1, rs(L) - rs(L - 1) - 1)
ElseIf L = 1 Then
GetStr = Left(str, rs(L) - 1)
ElseIf L > J Then
MsgBox "超出数据范围"
End If
End Function
For i = 0 To UBound(Split(strMyStr, "-", -1), 1)
strTemp = Trim(Split(strMyStr, "-", -1)(i))
If strTemp <> "" Then
Debug.Print Split(strTemp, " ", -1)(0)
Debug.Print Split(strTemp & " ", " ", -1)(UBound(Split(strTemp & " ", " ", -1), 1) - 1) & "-"
End If
Next
End Sub作者: Benjamin_luk 时间: 2006-4-11 06:21
帮到底了,再修改如下,已取得a b值了:
Function GetStr()
Dim str, str1, I As Integer, J As Integer, rs(99), K As Integer, a, b
str = " 4 4- 5 5- 6 6- 7 7- 8 8- 9 9- 10 10- 11 11- 12 12- 13 13- 1 1- 2 2- 3 3-"
str = (Replace(Trim(str), " ", ","))
''Replace space
Do Until InStr(1, str, ",,", 1) = 0
str = (Replace(str, ",,", ","))
str = str
Loop
str = str & ","
''Get "," position
For I = 1 To Len(str)
If Mid(str, I, 1) = "," Then
J = J + 1
rs(J) = I
End If
Next I
I = 1
''Get string
If J Mod 2 = 0 Then
For K = 2 To J Step 2
L = K - 1
'//取得A B 值
a = Mid(str, rs(L - 1) + 1, rs(L) - rs(L - 1) - 1)
b = Mid(str, rs(K - 1) + 1, rs(K) - rs(K - 1) - 1)
MsgBox "(" & a & "," & b & ")"
Next K
End If
End Function作者: msf 时间: 2006-4-11 16:27 LTrim,RTrim,及 Trim 函数示例
本示例使用 LTrim 及 RTrim 函数将某字符串的开头及结尾的空格全部去除。事实上只使用 Trim 函数也可以做到将两头空格全部去除。
Function GetStar()
Dim str, str1, I As Integer, J As Integer, rs(99), K As Integer
Dim ds(99, 99) As Variant, H As Integer, AB(99) As Variant
str = " 4 4- 5 5- 6 6- 7 7- 8 8- 9 9- 10 10- 11 11- 12 12- 13 13- 1 1- 2 2- 3 3-"
str = (Replace(Trim(str), " ", ","))
''Replace space
Do Until InStr(1, str, ",,", 1) = 0
str = (Replace(str, ",,", ","))
str = str
Loop
str = str & ","
''Get "," position
For I = 1 To Len(str)
If Mid(str, I, 1) = "," Then
J = J + 1
rs(J) = I
End If
Next I
I = 1
''Get string
H = 0
L = 0
If J Mod 2 = 0 Then
For L = 1 To J
AB(L) = (Mid(str, rs(L - 1) + 1, rs(L) - rs(L - 1) - 1))
Next L
'将数据保存到1维数组AB():
'4, 数组引用: ab(1)
'4- 数组引用: ab(2)
End If
MsgBox AB(2)
End Function作者: fan0217 时间: 2006-4-11 20:49