!!!vb比较字符串的问题。有三个text,一个按钮,如何在text3中显示text1和text2中文本不同的地方呢?
3个回答
展开全部
以下代码经测试可行
Private Sub Command1_Click()
Dim strA, strB, strC, strRe, strRes
'-----从text2中找出和text1重复的部分-----
strA = Text1.Text
strB = Text2.Text
For i = 1 To Len(strA)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strB
'-----从text1中找出和text2重复的部分-----
strA = Text2.Text
strB = Text1.Text
For i = 1 To Len(strB)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strC & strB
'-----过滤结果中重复的部分-----
For i = 1 To Len(strC)
strRe = Mid(strC, i, 1)
strRes = Replace(strC, strRe, "", , 1)
If InStr(1, strRes, strRe, vbTextCompare) <> 0 Then
strC = Replace(strRes, strRe, "") & strRe
End If
Next
Text3.Text = strC
End Sub
Private Sub Command1_Click()
Dim strA, strB, strC, strRe, strRes
'-----从text2中找出和text1重复的部分-----
strA = Text1.Text
strB = Text2.Text
For i = 1 To Len(strA)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strB
'-----从text1中找出和text2重复的部分-----
strA = Text2.Text
strB = Text1.Text
For i = 1 To Len(strB)
strB = Replace(strB, Mid(strA, i, 1), "")
Next
strC = strC & strB
'-----过滤结果中重复的部分-----
For i = 1 To Len(strC)
strRe = Mid(strC, i, 1)
strRes = Replace(strC, strRe, "", , 1)
If InStr(1, strRes, strRe, vbTextCompare) <> 0 Then
strC = Replace(strRes, strRe, "") & strRe
End If
Next
Text3.Text = strC
End Sub
展开全部
给个参考:
Private Sub Command1_Click()
Dim aa() As String
Dim bb() As String
Dim a As Integer
Dim b As Integer
Dim i As Integer
a = Len(Text1.Text)
b = Len(Text2.Text)
ReDim aa(a - 1)
For i = 0 To a - 1
aa(i) = Mid(Text1.Text, i + 1, 1)
Next
ReDim bb(b - 1)
For i = 0 To b - 1
bb(i) = Mid(Text2.Text, i + 1, 1)
Next
For i = 0 To a - 1
If aa(i) <> bb(i) Then
Text3.Text = Text3.Text & aa(i)
End If
Next
End Sub
Private Sub Form_Load()
Text1.Text = "122"
Text2.Text = "133"
Text3.Text = ""
End Sub
Private Sub Command1_Click()
Dim aa() As String
Dim bb() As String
Dim a As Integer
Dim b As Integer
Dim i As Integer
a = Len(Text1.Text)
b = Len(Text2.Text)
ReDim aa(a - 1)
For i = 0 To a - 1
aa(i) = Mid(Text1.Text, i + 1, 1)
Next
ReDim bb(b - 1)
For i = 0 To b - 1
bb(i) = Mid(Text2.Text, i + 1, 1)
Next
For i = 0 To a - 1
If aa(i) <> bb(i) Then
Text3.Text = Text3.Text & aa(i)
End If
Next
End Sub
Private Sub Form_Load()
Text1.Text = "122"
Text2.Text = "133"
Text3.Text = ""
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
无聊.先去百度搜索其它的答案.没搜索再来提问.
我上百度半个月.发现提这种问N次
我上百度半个月.发现提这种问N次
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询