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

Drop part of a line

 
E Jen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic