Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to count leading tabs (\t ) for a String

 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a simple method to count leading tabs(\t) for a String passed.

Should i use regex?Or is there another faster way?
regex =\\t*[^\\t]+
leading tabs Count =no of occurences of this pattern in the string

Thanks


 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be pretty easy to write some plain ordinary code which examined the characters of the string one at a time, wouldn't it? So how long would you expect it to take you? Could you do it in a minute? 5 minutes?

Okay, now how long is it going to take you to get a working regex? If that's a working regex that you have there then use it. That would be faster than spending the time to write the plain ordinary code. On the other hand if it isn't, and you maybe aren't very good at regex, then it would probably take you longer to get a working regex than to write the plain ordinary code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic