Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a char on a String and Float question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to find the number of "*" that there are on a string, what would be the best way to do it? The String object doesn't seem to have methods for this, how would you do it?

EX:

String test = "aaa* bbb* ccc"

int counter = Count("*",test);

counter should return 3.

Also is there a straight ahead way to convert a float like 1,22 to 1.22 if the default decimal separator of the system is "." and vice-versa?

Regards
 
counter=0;
int i=0;
while(test.indexOf("*",i)!=-1)
{
i=test.indexOf("*",i);
counter++;
}

You could also use a StringTokenizer and count
the tokens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top