Open The Text File

  • Thread starter Thread starter mipakteh
  • Start date Start date
M

mipakteh

Guest
Hi All,

My target is count strings from text file.Trying opening text file with 2 way.My question is why different result we get.

1.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Textfile=9121,0418,3275,9018,6228,7070,3576,0196,6804,5952,5414,4286,8483,4595,0915,1736,6414,4249,2035,6579,5051,4821,0014
5780,8932,0137,8165,9337,4895,9164,4314,4931,1373,3046,2677,5193,4258,2355,5929,2375,8646,4817,0447,1760,0085,6093


Dim StringToCheck As String = My.Computer.FileSystem.ReadAllText("C:\Users\user\Documents\AA.txt")

StringToCheck = StringToCheck.Replace(vbCrLf, ",")

Dim StringsToCheck As String() = StringToCheck.Split(","c)

For Each S As String In StringsToCheck

Dim StringsToFind As String() = {S(0) & S(1), _
S(0) & S(2), _
S(0) & S(3), _
S(1) & S(2), _
S(1) & S(3), _
S(2) & S(3)}

Dim Count As Integer = 0
For Each Find As String In StringsToFind
Count = 0
For Each Check As String In StringsToCheck
Select Case (Find.Count)
Case 2
If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) Then Count += 1
Case 3
If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) AndAlso Check.Contains(Find(2)) Then Count += 1
Case 4
If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) AndAlso Check.Contains(Find(2)) AndAlso Check.Contains(Find(3)) Then Count += 1

End Select
Next
ListBox1.Items.Add("Occurances (" & S & ", " & Find & ")= " & Count.ToString)

Next
Next

End Sub


2.

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

Textfile=9121,0418,3275,9018,6228,7070,3576,0196,6804,5952,5414,4286,8483,4595,0915,1736,6414,4249,2035,6579,5051,4821,0014
5780,8932,0137,8165,9337,4895,9164,4314,4931,1373,3046,2677,5193,4258,2355,5929,2375,8646,4817,0447,1760,0085,6093

Dim sr As New System.IO.StreamReader("C:\Users\user\Documents\AA.txt")
Do While sr.Peek <> -1
Dim StringToCheck As String = sr.ReadLine()

StringToCheck = StringToCheck.Replace(vbCrLf, ",")
Dim StringsToCheck As String() = StringToCheck.Split(","c)

For Each S As String In StringsToCheck
0123
Dim StringsToFind As String() = {S(0) & S(1), _
S(0) & S(2), _
S(0) & S(3), _
S(1) & S(2), _
S(1) & S(3), _
S(2) & S(3)}

Dim Count As Integer = 0
For Each Find As String In StringsToFind
Count = 0
For Each Check As String In StringsToCheck
Select Case (Find.Count)
Case 2
If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) Then Count += 1
Case 3
If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) AndAlso Check.Contains(Find(2)) Then Count += 1
Case 4
If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) AndAlso Check.Contains(Find(2)) AndAlso Check.Contains(Find(3)) Then Count += 1

End Select
Next
ListBox5.Items.Add("Occurances (" & S & ", " & Find & ")= " & Count.ToString & vbCrLf)
Next
Next


Loop
End Sub

353825d51768694f1d0273e3f9fa9e0b._.png


Continue reading...
 
Back
Top