怎么删除文本中重复段落 用vb
2010-8-2519:21:13xxxxxxxxxxxxxx2010-8-2519:22:52yyyyyyyyyyyyyy2010-8-2519:23:47xxxxxx...
2010-8-25 19:21:13
xxxxxxxxxxxxxx
2010-8-25 19:22:52
yyyyyyyyyyyyyy
2010-8-25 19:23:47
xxxxxxxxxxxxxx
2010-8-25 19:24:47
xxxxxxxxxxxxxx
2010-8-25 19:25:02
yyyyyyyyyyyyyy
2010-8-25 19:30:36
zzzzzzzzzzzzz 展开
xxxxxxxxxxxxxx
2010-8-25 19:22:52
yyyyyyyyyyyyyy
2010-8-25 19:23:47
xxxxxxxxxxxxxx
2010-8-25 19:24:47
xxxxxxxxxxxxxx
2010-8-25 19:25:02
yyyyyyyyyyyyyy
2010-8-25 19:30:36
zzzzzzzzzzzzz 展开
2个回答
展开全部
'以下程序经VB测试成功
Private Sub Command1_Click()
Dim a() As String, str As String, k As Integer
Static n%
'获取文本行数
Open "data.txt" For Input As #1
Do While Not EOF(1)
n = n + 1
Input #1, str
Loop
Close #1
'把每一行的内容存在数组里
ReDim a(n)
Open "data.txt" For Input As #1
Do While Not EOF(1)
i = i + 1
Input #1, a(i)
Loop
Close #1
'把不为空的内容重新存在数组里
For i = 1 To n
If a(i) <> "" Then
k = k + 1
a(k) = a(i)
End If
Next i
'如果内容相同,则该行为空
For i = 1 To k - 1
m = i
For j = i + 1 To k
If a(m) = a(j) Then a(j - 1) = "": a(j) = ""
Next j
Next i
'清空原文本内容
Open "data.txt" For Output As #1
Do While Not EOF(1)
Print #1, ""
Loop
Close #1
'将不为空的内容重新写入文本
For i = 1 To k
Open "data.txt" For Append As #1
If a(i) <> "" Then Print #1, a(i)
Close #1
Next i
End Sub
Private Sub Command1_Click()
Dim a() As String, str As String, k As Integer
Static n%
'获取文本行数
Open "data.txt" For Input As #1
Do While Not EOF(1)
n = n + 1
Input #1, str
Loop
Close #1
'把每一行的内容存在数组里
ReDim a(n)
Open "data.txt" For Input As #1
Do While Not EOF(1)
i = i + 1
Input #1, a(i)
Loop
Close #1
'把不为空的内容重新存在数组里
For i = 1 To n
If a(i) <> "" Then
k = k + 1
a(k) = a(i)
End If
Next i
'如果内容相同,则该行为空
For i = 1 To k - 1
m = i
For j = i + 1 To k
If a(m) = a(j) Then a(j - 1) = "": a(j) = ""
Next j
Next i
'清空原文本内容
Open "data.txt" For Output As #1
Do While Not EOF(1)
Print #1, ""
Loop
Close #1
'将不为空的内容重新写入文本
For i = 1 To k
Open "data.txt" For Append As #1
If a(i) <> "" Then Print #1, a(i)
Close #1
Next i
End Sub
展开全部
Private Sub Command1_Click()
Dim myTempStr As String, myOutputStr As String, myFile As String
myFile = "C:\123.txt" '文件路径
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, myTempStr
If InStr(1, myOutputStr, myTempStr) = 0 Then myOutputStr = myOutputStr & myTempStr & vbCrLf
Loop
Close
Open myFile For Output As #1
Print #1, myOutputStr
Close
End Sub
Dim myTempStr As String, myOutputStr As String, myFile As String
myFile = "C:\123.txt" '文件路径
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, myTempStr
If InStr(1, myOutputStr, myTempStr) = 0 Then myOutputStr = myOutputStr & myTempStr & vbCrLf
Loop
Close
Open myFile For Output As #1
Print #1, myOutputStr
Close
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询