Question String Counting

TommyEvans

Active member
Joined
Feb 19, 2010
Messages
39
Programming Experience
Beginner
Alright. I have a project I need to complete by 11:00 am today. I need a program that will allow a user to input a phrase into a text box. Another text box to input a letter. Then I need the program to count how many times, the letter appears in the phrase. I have everything set up. I know how to count how many characters are in the string, but not how many designated letters there is. Anyone have any idea?
 
You can use LINQs Count method.

VB.NET:
        Dim inputString As String = "Peter Piper picked a peck of pickled peppers"
        Dim searchChar As Char = "p"c
        Dim result = inputString.ToLower.Count(Function(ch) ch = searchChar)
 
Just take the entries from the textboxes rather than hard coding them in.

VB.NET:
        Dim inputString As String = txtInputPhrase.Text.ToLower
        Dim searchChar As Char = CChar(txtSearchChar.Text.ToLower)
        Dim result = inputString.ToLower.Count(Function(ch) ch = searchChar)
 
Back
Top