سؤال

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

هل كانت مفيدة؟

المحلول

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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top