Java - Count number of symbols in string -
let's have string:
string helloworld = "one,two,three,four!";
how can make counts number of commas in string helloworld
?
the simplest way iterate through string , count them.
int commas = 0; for(int = 0; < helloworld.length(); i++) { if(helloworld.charat(i) == ',') commas++; } system.out.println(helloworld + " has " + commas + " commas!");
Comments
Post a Comment