Home > Software engineering >  How do I remove a string repeat each separated by a newline character string
How do I remove a string repeat each separated by a newline character string

Time:10-01

Such as
1
2
3
1
2
3

After delete duplicates:
1
2
3

Requirements deal with larger data such as thousands of Numbers

CodePudding user response:

 
Private Sub XTMP ()

Dim arrNumber () As String
Dim arrCache () As String

Dim sResource As String
Dim s As String
Dim bFound As Boolean
Dim As Integer I
Dim j As Integer
Dim As Integer k
Dim iCount the As Integer

SResource="1, 2, 3, 2, 3, 4, 1, 2,"

ArrNumber=Split (sResource, "")
ICount=0

For I=LBound (arrNumber) To UBound (arrNumber)
S=arrNumber (I)
BFound=False
If iCount & gt; 0 Then
For j=LBound (arrCache) To UBound (arrCache)
If arrCache (j)=s Then
BFound=True
The Exit For
End the If
Next
End the If
If bFound=False Then
ReDim Preserve arrCache (iCount) As String
ArrCache (iCount)=s
ICount=iCount + 1
End the If
Next

For I=LBound (arrCache) To UBound (arrCache)
The Debug. Print arrCache (I)
Next

End Sub

CodePudding user response:

This way of dealing with the big data will have other such as regular expressions or slow API function to deal with it

CodePudding user response:

Use a dictionary within 50000 efficiency should be no problem, the above need to be flexible, otherwise the efficiency is not high

CodePudding user response:

Use a ListBox example:
 
Private Declare Function SendMessagebyString Lib _
"User32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long As String)

Private Const LB_FINDSTRINGEXACT=& amp; H1A2 'precise search in the ListBox

Private Sub Command1_Click ()
Dim TMP As String, As Long I
The Open yourfile. TXT "For Input As # 1
List1. Clear
Do Until EOF (1)
The Line Input # 1, TMP
If 1=SendMessagebyString (List1. HWnd LB_FINDSTRINGEXACT, 1, TMP) Then List1. AddItem TMP
Loop
Close # 1

Open "newfile. TXT" For the Output As the # 1
For I=0 To List1. ListCount - 1
Print # 1, List1. List (I)
Next I
Cose # 1
End Sub
  • Related