29-11-16, 04:02 AM
عفوا للمداخلة
ولكنني دائما ما أعتقد انه ومن الأفضل كتابة الكود علي هيئة كلاسات حتي يتثني للمبرمج استخدامها في أكثر من برنامج
لذلك قمت بكتابة الكلاس التالي بحيث يمكن استخدامه لإجابة سؤالك
الكلاس من الممكن تطويره سواء باستخدام Linq او بأي اسلوب اخر او يمكن استخدامه كما هو
الإستخدام
ولكنني دائما ما أعتقد انه ومن الأفضل كتابة الكود علي هيئة كلاسات حتي يتثني للمبرمج استخدامها في أكثر من برنامج
لذلك قمت بكتابة الكلاس التالي بحيث يمكن استخدامه لإجابة سؤالك
الكلاس من الممكن تطويره سواء باستخدام Linq او بأي اسلوب اخر او يمكن استخدامه كما هو
PHP كود :
Public Class CounterContext
Private Const sep As String = " "c
Private _values As List(Of String)
Private _keys As List(Of Integer)
Private _current As String
Public Sub New(s As String)
_current = s
End Sub
Protected ReadOnly Property Values() As List(Of String)
Get
If Me._values Is Nothing Then
Me._values = New List(Of String)()
If Not String.IsNullOrEmpty(_current) Then
For Each current As String In _current.Split(sep)
If Not _values.Contains(current) Then
_values.Add(current)
End If
Next
End If
End If
Return Me._values
End Get
End Property
Protected ReadOnly Property Keys() As List(Of Integer)
Get
If Me._keys Is Nothing Then
Me._keys = New List(Of Integer)()
If Not String.IsNullOrEmpty(_current) Then
For Each v As String In Values
Dim key As Integer = 0
For Each s As String In _current.Split(sep)
If v = s Then
key += 1
End If
Next
_keys.Add(key)
Next
End If
End If
Return Me._keys
End Get
End Property
Public ReadOnly Property Counter As String
Get
Dim _result As String = ""
For i As Integer = 0 To Keys.Count - 1
_result += String.Format("{0}", Keys(i))
Next
Return _result
End Get
End Property
End Class
الإستخدام
PHP كود :
Dim c As CounterContext = New CounterContext(TextBox1.Text)
Dim result As String = c.Counter

