aspose file tools*
The moose likes Beginning Java and the fly likes Need to count leading tabs (\t ) for a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need to count leading tabs (\t ) for a String" Watch "Need to count leading tabs (\t ) for a String" New topic
Author

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

Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
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
Bartender

Joined: Oct 14, 2005
Posts: 18658
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to count leading tabs (\t ) for a String