+ 2
How can I count the number of a letter in a string
for example,, input a string and count the number of 'A' in it.
8 Answers
+ 14
#include <iostream>
using namespace std;
int main() {
string str="hello #world";
int i,l=0;
for(i=0;i<str.length();i++){
if(str[i]!=' '&&(str[i]>='a'&&str[i]<='z')) l++;
}
cout << l;
return 0;
}
//haha , every language is similiar to java & easy âș
+ 12
@Samrad , he asked for C++
//not for javascript ,
btw still I found no link of it with the question needs
+ 1
in java:
char[] letters = string.split("");
int count = 0;
for(char c : letters){
if(c == 'A') count++;
}
+ 1
@Gaurav
Ok,
I thought Question in JS for loops
0
in c++ if u please and also,, what if the string has no A thanks
0
i dont know much c++ but its rather similar.
and if there is no 'A' the count would obviously be 0.
0
OK thanks
0
thanks