Hi I need help with this, supposed to be when i input a string example "ab12*&" there are three output
Number of Letters: 2
number of Integers: 2
number of Special Character: 2

but my program shows the number of character

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As Integer
        Dim stri As String
        Dim int As Integer
        Dim str As Integer
        Dim spe As Integer
        stri = TextBox1.Text
        For x = 0 To stri.Length - 1
            x.ToString()
            If IsNumeric(x) = False Then
                int += 1
            ElseIf IsNumeric(x) = True Then
                str += 1
            Else
                spe += 1
            End If
        Next
        Label5.Text = int
        Label6.Text = str
        Label7.Text = spe
    End Sub

Hi,

Try something like this

Dim x As Integer
        Dim stri As String
        Dim int As Integer
        Dim str As Integer
        Dim spe As Integer
        stri = TextBox1.Text
        For x = 0 To stri.Length - 1

            If IsNumeric(stri.Substring(x, 1)) = True Then
                int += 1
            ElseIf IsNumeric(stri.Substring(x, 1)) = False Then
                str += 1
            Else
                spe += 1
            End If
        Next
        MsgBox(int & " " & str & " " & spe)

It wont give count for special charecters as in second condition is checkig for Isnumeric=False will add the count to Str only. Try how to find special charecters in .net. this is just a hint. happy coding...:)

I think a clearer solution is

Dim s As String = "ab12*&"

        Dim numint As Integer = 0
        Dim numlet As Integer = 0
        Dim numspe As Integer = 0

        For Each letter As Char In s.ToUpper

            Select Case letter
                Case "A" To "Z"
                    numlet += 1
                Case "0" To "9"
                    numint += 1
                Case Else
                    numspe += 1
            End Select

        Next

        Debug.WriteLine("num int = " & numint)
        Debug.WriteLine("num let = " & numlet)
        Debug.WriteLine("num spe = " & numspe)

Edited 5 Years Ago by Reverend Jim: formatting change

Hi Reverend Jim,
I thought just to give him the diretion not sollution. so that he can put his efforts.

This article has been dead for over six months. Start a new discussion instead.