By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,419 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

max number of consecutive dot in a text file ?

P: 2
I have a text file : electron.txt
I want to count the max number of consecutive dots "." in the above text file,

dot is not a character, how to parse the line string returned from the text file to count dots. ?

please your help is appreciated.
Oct 1 '13 #1
Share this Question
Share on Google+
2 Replies

P: 94
Hi, mlotfi. I believe '.' is, or at least can be viewed as, a character. You can access a character at a specified position in a String using the method charAt on the String, sending to the method as an argument the position you want in the String. Some info about this method can be found here:
Oct 1 '13 #2

P: 13,264
What do you mean by max number of consecutive dots? Do you just mean number of consecutive dots (without the max part)?
If a line contains .... is that counted as one occurrence of consecutive dots or three occurrences ([..]..) , (.[..].), (..[..])?

Depending on what is you are actually looking for, you could use a regex expression for the matching, e.g
Expand|Select|Wrap|Line Numbers
  1.  final Pattern p = Pattern.compile("(\\.{2,})");
  2.         final Matcher matcher = p.matcher("");
  3.         while (matcher.find()) {
  4.             System.out.println("found: " +;
  5.         }
Oct 3 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.