大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Command1_Click()
在西山等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站建设、网站制作 网站设计制作按需求定制设计,公司网站建设,企业网站建设,品牌网站制作,成都全网营销推广,外贸营销网站建设,西山网站建设费用合理。
Dim fn As Integer, str1 As String, str2 As String, tmp1, tmp2, i As Integer
fn = FreeFile
Open "d:\文本1.txt" For Binary As #fn
str1 = Input(LOF(fn), fn)
tmp1 = Split(str1, vbCrLf, -1)
Close #fn
fn = FreeFile
Open "d:\文本2.txt" For Binary As #fn
str2 = Input(LOF(fn), fn)
tmp2 = Split(str2, vbCrLf, -1)
Close #fn
'把文件1内的值与tmp2数组内每个值、相同的消去
For i = LBound(tmp2) To UBound(tmp2)
str1 = Replace(str1, tmp2(i) vbCrLf, "", 1, -1, vbBinaryCompare)
Next i
'把文件2内的值与tmp1数组内每个值、相同的消去
For i = LBound(tmp1) To UBound(tmp1)
str2 = Replace(str2, tmp1(i) vbCrLf, "", 1, -1, vbBinaryCompare)
Next i
'textBox 设置MultiLine = True , ScrollBars = 3
'显示的是没有被互相消去的“行值”
Text1.Text = str1
Text2.Text = str2
'以上操作不影响文件的改变,如果要回存,直接Open OutPut 语句回存即可。
End Sub
这个好象是书里第三章的内容把
用当循环或FOR循环,每次循环比较text1和text2中的数据
如果相等
static s as integer
s=0
a=text1.text
b=text2.text
c=text3.text
d=text4.text
如果相等
to:
s=s+1
for i=mid$(text1.text,s,1)and mid$(text2.text,s,1)
if i=true then c=text1.text,d=text1.text 或c=text1.text,d=text1.text
c=mid$(text1.text,1,1)或mid$(text2.text,1,1)
if len(text1.text或text2.text) 或 lne(text1.text)或len(text2.text) then
Exit
end if
next
for i=mid$(text1.text)mid$(text2.text)
d=text1.text...或text2.text...
goto to
If System.IO.File.ReadAllBytes(文件名1).SequenceEqual(System.IO.File.ReadAllBytes(文件名2)) Then
相等
Else
不相等
End If
刚写完一个简单的例子,给你作个参考吧。希望对你有帮助。
Private Function compFile(strName1 As String, strName2 As String) As Integer
Dim i As Long, j As Long
Dim A1 As Byte, A2 As Byte
Dim FNO1 As Integer, FNO2 As Integer
Dim LNo As Long
FNO1 = FreeFile()
Open strName1 For Binary As FNO1
FNO2 = FreeFile()
Open strName2 For Binary As FNO2
If LOF(FNO1) = LOF(FNO2) Then '取文件小的那个文件的大小作为标准
LNo = LOF(FNO1)
Else
LNo = LOF(FNO2)
End If
For i = 1 To LNo
Get FNO1, i, A1
Get FNO2, i, A2
'读出了数据,可以开始比较并加入相映的处理操作了。
'这里是例子
If A1 A2 Then
MsgBox "在两个文件的第 " i "字节处不匹配"
Close
compFile = 1
Exit Function
End If
Next i
End Function
在每次text2换行时进行检测(就是按下回车键时),代码如下
Private Sub Text2_Keydown(KeyCode As Integer, Shift As Integer)
Dim lngCrlf As String
If KeyCode = vbKeyReturn Then
lngCrlf = InStrRev(Text2.Text, vbCrLf)
If lngCrlf 0 Then
If Mid(Text2.Text, lngCrlf + 2, Len(Text2.Text)) = Text1.Text Then MsgBox "与text1一样"
ElseIf lngCrlf = 0 Then
If Text2.Text = Text1.Text Then MsgBox "与text一样"
End If
End If
End Sub
Private Sub Form_Load()
Text1.Text = "112233"
Text2.Text = ""
End Sub
vb.net规定如果要比较字符串,不能用“=”,strcomp(str1,str2,n)或者string.compare(str1,str2)
例如:
Dim a As String = "c"
Dim b As String = "c"
Dim n As Integer = String.Compare(a, b)
If n = 0 Then
MsgBox("=")
Else
MsgBox("")
End If