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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -