Question

I need to know the count of a character in a String Variable. It's possible in PHP with substrcount.

Now, what's Equivalent substrcount in android(java)?

Edited :

For example count of (:) in

  String a="abc:def:gh:test"

---------> count of (:) = 3

Was it helpful?

Solution

Yes StringTokenizer is there, You can try following way,

String str = "abc:def:gh:test";
StringTokenizer st = new StringTokenizer(str,":");
int count = st.countTokens() - 1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top