有字符串1 "9 1 10 6 13"
另一字符串2 "9 10 11 12 13"查找字符串1中是否 有任意3个数字 在字符串2中 例子中 9 10 13为这3个数
如果有则 则显示出"有3个数相同" 并且显示出字符串2中另外2个数字 例子中为11 12有好的方法编程得到吗?
谢了
另一字符串2 "9 10 11 12 13"查找字符串1中是否 有任意3个数字 在字符串2中 例子中 9 10 13为这3个数
如果有则 则显示出"有3个数相同" 并且显示出字符串2中另外2个数字 例子中为11 12有好的方法编程得到吗?
谢了
解决方案 »
- ado控件+datagrid 点查询提示refresh的方法Iadodc失败是什么问题
- 又是vb操作ini,请使用API
- 如何去看别人的程序 请有经验的程序员指教
- 请问怎么用代码实现,读取MP3的比特率、频率和时间?
- 哪有msado26.ocx 下载,急!
- 请问有没有报表控件,能够画线,并且能从多个表中读数据.在线等待,解决立即给分
- 高手请进,关于AotoCAD超链的问题
- 请问
- 如何在启动IE时启动自己写的程序??
- 怎样读取一个随机存储文件……
- 急求 vba中是否能用sendmessage函数???
- GetMenuContextHelpId 这个函数似乎无法获得VB菜单编辑器中设置的HelpContextId值,谁知道这里改用那个API函数啊?
Dim tempStr1() As String, tempStr2() As String
Dim Str1 As String, Str2 As String, temp As String
Dim i As Integer, j As Integer, N As Integer, F() As Boolean
Str1 = "9 1 10 6 13"
Str2 = "9 10 11 12 13"
tempStr1 = Split(Str1)
tempStr2 = Split(Str2)
ReDim F(UBound(tempStr2))
For i = 0 To UBound(tempStr1)
For j = 0 To UBound(tempStr2)
If tempStr1(i) = tempStr2(j) Then
F(j) = True
N = N + 1
End If
Next j
Next i
If N = 3 Then
For i = 0 To UBound(tempStr2)
If Not F(i) Then temp = temp + tempStr2(i) + " "
Next i
MsgBox "有3个数据相同,不同数为:" & temp
End If
b = "9 10 11 12 13" arr_a = split(a," ")
arr_b = split(b," ")set dict = createobject("scripting.dictionary")
for i=lbound(arr_b) to ubound(arr_b)
call dict.add(arr_b(i),null)
nextfor i=lbound(arr_a) to ubound(arr_a)
if dict.exists(arr_a(i)) then
call msgbox(arr_a(i))
end if
next
将以上代码复制到记事本中,保存为test.vbs,然后双击运行即可.
b = "9 10 11 12 13" arr_a = split(a," ")
arr_b = split(b," ")for i=lbound(arr_a) to ubound(arr_a)
For j=LBound(arr_b) To UBound(arr_b)
If arr_a(i) = arr_b(j) Then
Call MsgBox(arr_a(i))
End If
Next
Next
这样也可以:->
S1 = "9 1 10 6 13"
S2 = "9 10 11 12 13"
A = Split(S1, " ")
B = Split(S2, " ")
For i = 0 To UBound(A)
For J = 0 To UBound(A)
If A(i) = B(J) Then
k = k + 1
Debug.Print A(i)
End If
Next
Next
Debug.Print "有" & k & "个数相同"
End Sub
Dim S1() As String, S2() As String, S3() As String
Dim S As String
Dim i As Integer, j As Integer, m As Integer, n As Integer
Str1 = "9 1 10 6 13"
Str2 = "9 10 11 12 13"
S1 = Split(Str1, " "): S2 = Split(Str2, " ")
m = 0: n = 0
For i = 0 To UBound(S1)
For j = 0 To UBound(S2)
If Val(S1(i)) = Val(S2(j)) Then
m = m + 1: S = S & (S1(i) & " ")
Debug.Print "相同的数是:" & S1(i)
End If
Next
Next
n = UBound(S2) + 1 - m
S3 = Split(S, " ")
For i = 0 To UBound(S2)
For j = 0 To UBound(S3)
If Val(S2(i)) = Val(S3(j)) Then
S2(i) = ""
End If
Next
If Len(S2(i)) <> 0 Then Debug.Print "不相同的数是:" & S2(i)
Next
Debug.Print "共有" & m & "个相同的数!", "共有" & n & "个不相同的数!"
End Sub