用vb如何去掉重复的行?
用vb建立一个窗体,上面有两个文本框text1、text2(multiline属性都是true)和一个按钮command1。现在在文本框text1中输入如下有重复行的内容...
用vb建立一个窗体,上面有两个文本框text1、text2(multiline属性都是true)和一个按钮command1。现在在文本框text1中输入如下有重复行的内容(输入的行数不限,可能很多),在文本框text2中自动把那些重复的行去掉:
<a href="http://www.haoting.com/hao123/90.htm">追 (马三立)</a>
<a href="http://www.haoting.com/hao123/90.htm">追 (马三立)</a>
<a href="http://www.haoting.com/hao123/236.htm">走向世界 (李伯祥/杜国芝)</a>
<a href="http://www.haoting.com/hao123/236.htm">走向世界 (李伯祥/杜国芝)</a>
<a href="http://www.haoting.com/hao123/256.htm">爱的挫折 (姜昆、李文华)</a>
<a href="http://www.haoting.com/hao123/256.htm">爱的挫折 (姜昆、李文华)</a> 展开
<a href="http://www.haoting.com/hao123/90.htm">追 (马三立)</a>
<a href="http://www.haoting.com/hao123/90.htm">追 (马三立)</a>
<a href="http://www.haoting.com/hao123/236.htm">走向世界 (李伯祥/杜国芝)</a>
<a href="http://www.haoting.com/hao123/236.htm">走向世界 (李伯祥/杜国芝)</a>
<a href="http://www.haoting.com/hao123/256.htm">爱的挫折 (姜昆、李文华)</a>
<a href="http://www.haoting.com/hao123/256.htm">爱的挫折 (姜昆、李文华)</a> 展开
展开全部
我觉得这种问题不需要太多代码。
**********************************************************************
Private Sub Command1_Click()
Dim ObjStr, StrTemp, I%
Text2 = ""
StrTemp = Replace(Text1, vbCrLf, "||")
For Each ObjStr In Split(StrTemp, "||")
If InStr(StrTemp, ObjStr) Then StrTemp = Replace(StrTemp, ObjStr, ""): Text2 = Text2 & ObjStr & vbCrLf
Next
End Sub
**********************************************************************
**********************************************************************
Private Sub Command1_Click()
Dim ObjStr, StrTemp, I%
Text2 = ""
StrTemp = Replace(Text1, vbCrLf, "||")
For Each ObjStr In Split(StrTemp, "||")
If InStr(StrTemp, ObjStr) Then StrTemp = Replace(StrTemp, ObjStr, ""): Text2 = Text2 & ObjStr & vbCrLf
Next
End Sub
**********************************************************************
展开全部
不用其它组件的话只能放数组,然后一个一个比较....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a() As String, b As String, i%, j%
b = Text1
Open App.Path & "\1.txt" For Output As #1
Print #1, b
Close
Open App.Path & "\1.txt" For Input As #1
Do While Not EOF(1) '循环读取数据直到文件末尾
Line Input #1, b '每次读入一行文本数据
ReDim Preserve a(i) '重新定义动态数组
a(i) = b
If i > 1 Then
If a(i) <> a(i - 1) Then
i = i + 1
End If
Else
i = i + 1
End If
Loop
Close
For j = 0 To i - 1
For k = j + 1 To i - 1
If Trim(a(j)) = Trim(a(k)) Then
Exit For
ElseIf k = i - 1 Then
Text2 = Text2 & a(j) & vbCrLf
End If
Next
Next
kill App.Path & "\1.txt"
End Sub
Dim a() As String, b As String, i%, j%
b = Text1
Open App.Path & "\1.txt" For Output As #1
Print #1, b
Close
Open App.Path & "\1.txt" For Input As #1
Do While Not EOF(1) '循环读取数据直到文件末尾
Line Input #1, b '每次读入一行文本数据
ReDim Preserve a(i) '重新定义动态数组
a(i) = b
If i > 1 Then
If a(i) <> a(i - 1) Then
i = i + 1
End If
Else
i = i + 1
End If
Loop
Close
For j = 0 To i - 1
For k = j + 1 To i - 1
If Trim(a(j)) = Trim(a(k)) Then
Exit For
ElseIf k = i - 1 Then
Text2 = Text2 & a(j) & vbCrLf
End If
Next
Next
kill App.Path & "\1.txt"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询