I have a string of names where all the different names are seperated by the same character (#) e.g. tom#will#robert#
I want to be able to count the number of names by counting the number of times that # appears, How would i go about doing this?
I have a string of names where all the different names are seperated by the same character (#) e.g. tom#will#robert#
I want to be able to count the number of names by counting the number of times that # appears, How would i go about doing this?
You need:
yourstring.splt("#").length;
Why would you want to count the number of tokens by counting the number of the delimiters?
Just use StringTokenizer to get all tokens (set the delimiter as #) and then get its size.
StringTokenizer(String str, String delim)
Constructs a string tokenizer for the specified string.
then:
int countTokens()
Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.