如
1111
2222
3333
1111
2222
3333
用換行符把字串隔開
洗掉重復項后得到如下答案:
1111
2222
3333
求正則運算式
uj5u.com熱心網友回復:
Dictionary 物件描述
物件,用于存盤資料關鍵字和條目對。
語法
Scripting.Dictionary
說明
Dictionary 物件與 PERL 關聯陣列等價。可以是任何形式的資料的條目被存盤在陣列中。每個條目都與一個唯一的關鍵字相關聯。該關鍵字用來檢索單個條目,通常是整數或字串,可以是除陣列外的任何型別。
下面的代碼舉例說明了如何創建一個 Dictionary 物件:
Dim d '創建一個變數
Set d = CreateObject(Scripting.Dictionary)
d.Add "a", "Athens" '添加一些關鍵字和條目
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
...
uj5u.com熱心網友回復:
正則不是萬能的。別為了用正則而正則。這個場景是正則是無能為力的。 樓上說的字典方法是一個很有效并且快速篩選重復的辦法。下面提供一個我之前寫的VBS腳本。保存到文本檔案然后后綴名改成vbs就可以了
'描述:直接將要篩選相同行的檔案拖到這個vbs檔案上即可
'作者:sysdzw
'郵箱:[email protected]
'QQ:171977759
'12:51 2009-7-12
Dim strFileSource, strFileResult,t1
On Error Resume Next
strFileSource = wscript.Arguments(0)
strFileResult = Left(strFileSource, InStrRev(strFileSource, ".") - 1) & "_out.txt"
If strFileSource <> "" Then
t1=Time()
Set fso = CreateObject("scripting.filesystemobject")
Set stream = fso.opentextfile(strFileSource, 1, False)
Set stream2 = fso.opentextfile(strFileResult, 2, True)
Set dict = CreateObject("scripting.dictionary")
While Not stream.atendofstream
Line = stream.readline
If Not dict.Exists(Line) Then
Call dict.Add(Line, Null)
Call stream2.writeline(Line)
End If
Wend
stream.Close
stream2.Close
MsgBox "處理完畢!總計耗時 " & DateDiff("s",t1,Time) & " 秒。" & vbCrLf & vbCrLf & strFileResult, vbInformation, "Del Same Line QQ:171977759"
Else
MsgBox "no file!", vbExclamation, "Del Same Line QQ:171977759"
End If
uj5u.com熱心網友回復:

Option Explicit
Private Sub Command1_Click()
List1.Clear
Dim re As New RegExp
Dim ms As MatchCollection, m As Match, i As Integer, j As Integer
With re
.MultiLine = True
.Global = True
.IgnoreCase = True
.Pattern = "([^\n]+\n)"
Set ms = .Execute(Text1)
For i = 0 To ms.Count - 1
For j = 0 To i - 1
If ms(i) = ms(j) Then Exit For
Next
If j = i Then List1.AddItem ms(i)
Next
End With
Set re = Nothing
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/102501.html
標籤:非技術類
