Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Drop part of a line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Drop part of a line" Watch "Drop part of a line" New topic
Author

Drop part of a line

E Jen
Greenhorn

Joined: Oct 22, 2006
Posts: 5
I have some code written to read a chatlog file, one that you may find from an IM system. Most of the lines that are read look like this:

[10:34:46] MESSAGE HERE

How would I get it to drop the time stamp? The code I have currently written is:


[ October 22, 2006: Message edited by: E Jen ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
OK, this is weird. I see you have used code tags - good, thank you very much. And yet your code still seems to have almost no indentation. What's up? Do you not find it useful to indent your code to make it readable? I find it difficult to motivate myself to bother reading something if the author hasn't put at least a little effort into making it readable. Note that you can edit your post using the little icon at the top of the post. Thanks.


"I'm not back." - Bill Harding, Twister
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Use the methods available on the String object such as indexOf() and substring().

Or you can use regular expression to grab all of the characters after the sequence "] ".
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Considering the fact that in my experience in such a log file every single line is one message and the format is a strict [hh:mm:ss] where 9 is "09" it could be as simple as using String.substring(10) to get everything after the time stamp and the space which are a fixed size.
E Jen
Greenhorn

Joined: Oct 22, 2006
Posts: 5
Originally posted by Jim Yingst:
OK, this is weird. I see you have used code tags - good, thank you very much. And yet your code still seems to have almost no indentation. What's up? Do you not find it useful to indent your code to make it readable? I find it difficult to motivate myself to bother reading something if the author hasn't put at least a little effort into making it readable. Note that you can edit your post using the little icon at the top of the post. Thanks.

Sorry about that. Normally it is indented when I right it, somehow I messed that up. And thank you for all of your replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drop part of a line
 
Similar Threads
Please help me get started with this assignment
help with counting operands and operaters
Please help me get started with this assignment
BufferedReader in J2ME
Problems using/making method!