Home > Software engineering >  Vb how to determine whether two TXT have duplicate content
Vb how to determine whether two TXT have duplicate content

Time:11-12

FAI has repeated clear text content

CodePudding user response:

Please everyone a great god guide!

CodePudding user response:

Logic statements: if then else endif, do.. Loop, the for... Next
The split string handling functions, left, right, mid, len
Read and write files: the open statement
Basic on these can solve above, not using the F1 + baidu, if he too lazy to write directly bids,

CodePudding user response:

 
Dim str_array () As a String, _
Str_info As String, _
Bound_array As Long, _
I As Long, _
J As Long

Str_info="FAI5 FAI6, FAI4, FAI5, FAI6"
Str_array=Split (str_info, ", ")

Bound_array=UBound (str_array)
For I=0 To bound_array - 1
For j=I + 1 To bound_array
If str_array (I)=str_array (j) Then
Str_array (j)=str_array (bound_array)
Bound_array=bound_array - 1
ReDim Preserve str_array (bound_array)
J=j - 1
End the If
If j=bound_array Then
The Exit For
End the If
Next j
If I=bound_array Then
The Exit For
End the If
Next I

For I=0 To bound_array
The Debug. Print str_array (I)
Next I

CodePudding user response:

A great god, and I wanted to first TXT and second TXT checked, if there are repeated, remove the second TXT everything??

CodePudding user response:

reference 3 floor still human response:
 
Dim str_array () As a String, _
Str_info As String, _
Bound_array As Long, _
I As Long, _
J As Long

Str_info="FAI5 FAI6, FAI4, FAI5, FAI6"
Str_array=Split (str_info, ", ")

Bound_array=UBound (str_array)
For I=0 To bound_array - 1
For j=I + 1 To bound_array
If str_array (I)=str_array (j) Then
Str_array (j)=str_array (bound_array)
Bound_array=bound_array - 1
ReDim Preserve str_array (bound_array)
J=j - 1
End the If
If j=bound_array Then
The Exit For
End the If
Next j
If I=bound_array Then
The Exit For
End the If
Next I

For I=0 To bound_array
The Debug. Print str_array (I)
Next I

A great god, and I wanted to first TXT and second TXT checked, if there are repeated, remove the second TXT everything??

CodePudding user response:

I also wrote a, the code is as follows:
 
Option Explicit

Private Sub Command1_Click ()
Dim fso As Object
The Set of fso=CreateObject (" scripting. Filesystemobject ")

Dim ngfai As String
Ngfai=fso. Buildpath (App) Path, "ngfai. TXT")

Dim finalprint1 As String
Finalprint1=fso. Buildpath (App) Path, "finalprint1. TXT")

Dim objStream As Object
The Set objStream=fso. Opentextfile (finalprint1, 1, False)

Dim strfinalprint1 As String
If objStream. Atendofstream Then
Strfinalprint1=""
The Else
Strfinalprint1=objStream. Readall
End the If

ObjStream. Close

The Set objStream=fso. Opentextfile (ngfai, 1, False)

Dim blnFound As Boolean
BlnFound=False

Dim reg As Object
The Set reg=CreateObject (" vbscript. Regexp ")
Reg. Global=False
Reg. MultiLine=True
Reg. The ignorecase=True

The Do While Not objStream. Atendofstream
Dim strLine As String
StrLine=objStream. Readline

If strLine & lt;> "" Then
Reg. The Pattern="^" & amp; StrLine & amp; "\ b"
The (strfinalprint1) Then the If reg
BlnFound=True
The Exit Do
End the If
'the Debug. Print strLine
End the If
Loop

ObjStream. Close

If blnFound Then 'matches content, delete finalprint1. TXT file;
The Set objStream=fso. Opentextfile (finalprint1, 2, True)
ObjStream. Close
End the If

End Sub

Download address:
Link: https://pan.baidu.com/s/1c2wVUOfh-OLPAufeEVO8tA
The extracted code: o6yd
  • Related