Hello,
I use the code below to do some comparison among 2 strings (t1 and t2) :
Dim ar1 As String() = Split(t1, ",")
Dim ar2 As String() = Split(t2, ",")
Dim txtoutput As IEnumerable(Of String) = ar2.Except(ar1)
When I tested the app with t1(almost 1250000 characters) and t2(almost half of the t1 length) , txtoutput returned 0 (but there were actually around 7000 items in common with the input strings).
What's the maximum safe length of input to this method ? What's the maximum count of IEnumerable(Of String) ?
Thanks
P.S project link :
1z3tADujRhUeZ4VXWFNqnNALj5sfGQSL4
My form :
Imports System.ComponentModel
Imports System.Linq
Imports System.Text
Public Class Form1
Dim t1 As String
Dim t2 As String
Dim txtOutput As IEnumerable(Of String)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog
ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
ofd.Filter = "Text|*.txt"
If ofd.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
Try
t1 = My.Computer.FileSystem.ReadAllText(ofd.FileName)
oldLink.Text = Split(t1, ",").Length
TextBox1.Text = ofd.FileName
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim ofd As New OpenFileDialog
ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
ofd.Filter = "Text|*.txt"
If ofd.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
Try
t2 = My.Computer.FileSystem.ReadAllText(ofd.FileName)
newLink.Text = Split(t2, ",").Length
TextBox2.Text = ofd.FileName
Catch ex As Exception
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If TextBox1.Text <> "" And TextBox2.Text <> "" And TextBox3.Text <> "" Then
BackgroundWorker1.RunWorkerAsync()
End If
End Sub
Sub getOutputCount()
If InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf getOutputCount))
Else
finalLink.Text = txtOutput.Count
Application.DoEvents()
End If
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim splt() As Char = {","c}
Dim ar1 As List(Of String) = t1.Split(splt, StringSplitOptions.RemoveEmptyEntries).ToList
Dim ar2 As List(Of String) = t2.Split(splt, StringSplitOptions.RemoveEmptyEntries).ToList
ar1.Sort()
ar2.Sort()
txtOutput = ar2.Except(ar1)
getOutputCount()
Dim fTx2 As String = String.Join(",", txtOutput)
My.Computer.FileSystem.WriteAllText(TextBox3.Text, fTx2, True)
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MsgBox("Done!")
Button3.Enabled = False
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim ofd As New SaveFileDialog
ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
ofd.Filter = "Text|*.txt"
If ofd.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
Try
TextBox3.Text = ofd.FileName
Catch ex As Exception
End Try
End Sub
End Class