Checking String or Number in 2 class

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

mipakteh

Guest
Hi All,

I have 2 List Text1 and Text2.

I want to find if the number in class Text1 same in class Text2.

the number is 36 or 63, reverse number we declare as a same number. In Class Text2 have 5 of 36 or 63.

if find then TextBox3 show "YES" or counting that number.

Hope somebody can correct this code or teach something.

Thank.


Option Strict On
Option Explicit On
Public Class Form1

Private Items As New List(Of Text1)
Private Items_A As New List(Of Text2)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Items.Add(New Text1("3 ,6 ,"))
For i As Integer = 0 To Items.Count - 1
TextBox1.AppendText(Items(i).ToString & vbCrLf)
TextBox1.AppendText(vbCrLf)
Next

Items_A.Add(New Text2("23 ,21 ,21 ,31 ,31 ,11 ,34 ,36 ,31 ,46 ,41 ,61 ,19 ,16 ,15 ,96 ,95 ,65 ,25 ,25 ,23 ,55 ,53 ,53 ,83 ,86 ,83 ,36 ,33 ,63 ,15 ,14 ,10 ,54 ,50 ,40 ,19 ,16 ,19 ,96 ,99 ,69 ,83 ,88 ,85 ,38 ,35 ,85 ,12 ,18 ,11 ,28 ,21 ,81 ,58 ,58 ,55 ,88 ,85 ,85 ,49 ,45 ,41 ,95 ,91 ,51 ,88 ,86 ,82 ,86 ,82 ,62 ,58 ,53 ,50 ,83 ,80 ,30 ,78 ,74 ,75 ,84 ,85 ,45 ,62 ,63 ,69 ,23 ,29 ,39 ,09 ,02 ,07 ,92 ,97 ,27 ,51 ,54 ,54 ,14 ,14 ,44 ,77 ,70 ,73 ,70 ,73 ,03 ,65 ,62 ,65 ,52 ,55 ,25 ,60 ,61 ,61 ,01 ,01 ,11 ,61 ,65 ,63 ,15 ,13 ,53 ,85 ,82 ,82 ,52 ,52 ,22 ,82 ,82 ,81 ,22 ,21 ,21 ,"))

For i As Integer = 0 To Items_A.Count - 1
TextBox2.AppendText(Items_A(i).ToString & vbCrLf)
TextBox2.AppendText(vbCrLf)
Next


End Sub

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

Dim sb As New System.Text.StringBuilder
Dim counts As New Dictionary(Of String, Integer)

For J As Integer = 0 To Items.Count - 1
Dim entry As String = Items(J).str_
entry = entry.TrimEnd(CChar(","))
entry = entry.Replace(vbCrLf, ",")
entry = entry.Replace(" ", "")
entry = entry.Replace(",", "")
counts(entry) = 0

Next

For J As Integer = 0 To Items_A.Count - 1
Dim StringToCheck As String = Items_A(J).str_1

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

For Each S As String In StringsToCheck

Dim t As List(Of String) = New List(Of String)

t.Add(S.Substring(0, 1))
t.Add(S.Substring(1, 1))
t.Add(S.Remove(1, 1))
t.Add(S.Remove(1, 1))

For Each ts In t
For Each Find2 As Text1 In Items

Dim searchChars As New List(Of Char)(Find2.str_.ToCharArray)
For Each c As Char In ts
If searchChars.Contains(c) Then
searchChars.Remove(c)
If searchChars.Count = 0 Then Exit For
End If
Next
If searchChars.Count = 0 Then counts(Find2.str_) += 1
Next


Next


Next

Next
For Each key As String In (From k In counts.Keys Order By k)
If counts(key) > 0 Then
sb.AppendLine("Occurences (" & key & ")= " & counts(key).ToString)
Else
sb.AppendLine("Occurences (" & key & ")= nothing")
End If
Next
TextBox3.Text = sb.ToString

End Sub
End Class
Public Class Text1
Public Property str_ As String
Public Sub New(ByVal a As String)
str_ = a
End Sub
Public Overrides Function ToString() As String
Return str_
End Function
End Class
Public Class Text2
Public Property str_1 As String
Public Sub New(ByVal c As String)
str_1 = c
End Sub
Public Overrides Function ToString() As String
Return str_1
End Function
End Class

Continue reading...
 
Back
Top