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.
Thanks
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: http://docs.oracle.com/javase/6/docs...ng/String.html
Oct 1 '13 #2

10K+
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("...asd.f.....ee.fgfgf");
  3.         while (matcher.find()) {
  4.             System.out.println("found: " + matcher.group(1));
  5.         }
  6.  
Oct 3 '13 #3

Post your reply

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