PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 16 déc. 2008 à 15:44
salut,
pourquoi passer par 2 tableaux, pourquoi "200"
en passant par un tableau de byte tu n'as pas besoin de vérifier l'existance...
voici une modif pour lister la totalité, pose une listbox en font 'courier new' pour tester :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim aiChars() As Int32 = GetCharsCount(TextBox1.Text, True)
For i As Int32 = 0 To 255
If aiChars(i) > 0 Then ListBox1.Items.Add(Convert.ToChar(i) & " " & aiChars(i).ToString)
Next
End Sub
Function GetCharsCount(ByVal sText As String, Optional ByVal bUcase As Boolean = False) As Int32()
Dim aiRet(0 To 255) As Int32
If sText.Length > 0 Then
If bUcase Then sText = sText.ToUpper
Dim abChars() As Char = sText.ToCharArray
For i As Int32 = 0 To sText.Length - 1
aiRet(Convert.ToByte(abChars(i))) += 1
Next
End If
Return aiRet
End Function
pas forcément optimisé non plus mais çà me semble plus logique non?
++
16 déc. 2008 à 15:44
pourquoi passer par 2 tableaux, pourquoi "200"
en passant par un tableau de byte tu n'as pas besoin de vérifier l'existance...
voici une modif pour lister la totalité, pose une listbox en font 'courier new' pour tester :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim aiChars() As Int32 = GetCharsCount(TextBox1.Text, True)
For i As Int32 = 0 To 255
If aiChars(i) > 0 Then ListBox1.Items.Add(Convert.ToChar(i) & " " & aiChars(i).ToString)
Next
End Sub
Function GetCharsCount(ByVal sText As String, Optional ByVal bUcase As Boolean = False) As Int32()
Dim aiRet(0 To 255) As Int32
If sText.Length > 0 Then
If bUcase Then sText = sText.ToUpper
Dim abChars() As Char = sText.ToCharArray
For i As Int32 = 0 To sText.Length - 1
aiRet(Convert.ToByte(abChars(i))) += 1
Next
End If
Return aiRet
End Function
pas forcément optimisé non plus mais çà me semble plus logique non?
++