I tried googling some information about this, but I only found some on how to count the occurrences of a pre-defined pattern of a char/string to be searched. I just mixed some of the information I learned from some tutorials/forums I've visited.
I would like to know if there is an alternative solution for the
Dim qry As System.Collections.Generic.IEnumerable(Of Char) = _
From c As Char In origStr Select c Distinct
Dim trimmedStr As String = String.Join("", qry)`
to remove all the duplicated characters in a string?The above code really ???? me. This is my code for counting the occurrences of EACH character in a string.
Dim origStr As String
Console.Write("ENTER STRING HERE : ")
origStr = Console.ReadLine()
origStr = LCase(origStr)
' Remove dup chars
Dim qry As System.Collections.Generic.IEnumerable(Of Char) = _
From c As Char In origStr Select c Distinct
Dim trimmedStr As String = String.Join("", qry)
Dim counts(Len(trimmedStr) - 1) As Integer
Dim cnt As Integer = 0
origStr = Trim(origStr)
trimmedStr = Trim(trimmedStr)
Console.WriteLine(trimmedStr)
For i = 0 To Len(trimmedStr) - 1
For Each k As Char In origStr
If (trimmedStr(i) = k) Then
cnt += 1
End If
Next
counts(i) = cnt
cnt = 0
Console.WriteLine(trimmedStr(i) & " => " & counts(i))
Next
Console.ReadKey()