If I have a string of character in a String varible strText. If I want to count how many 'a' characters are in stored in the string.
I have a counter declared as int count_a and it's initialized to zero.
Once I have a line of text in the strText string.
My loop looks like this:
[FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]for[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] ([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] i = 0; i <= strText.length()-1; i++)
{
[/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf] if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (strText(i).equals("a"[/FONT][FONT=Courier New]))
{
count_a++;
} [/FONT]
[FONT=Courier New]}
[/FONT]
I get cannot find symbol error from compiler. I know this isn't the right way to set it up but I'm trying to use the equals command to compare the charaters in the string to see how many of the characters are an 'a'.


Sign In
Create Account


Back to top









