Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 5th, 2005, 11:21 AM   #1
firefly
Newbie
 
Join Date: Jun 2005
Posts: 3
Rep Power: 0 firefly is on a distinguished road
irc logger, string problem

I have an irc bot that works so far, i want it to log everything in the channel and output it to a text file.
The only problem is that i am rubbish at string manipulation .

How would i turn this string
":firefly!firefly@somerandomhost.com PRIVMSG #test : Hello"

in to something like this?:
"<firefly>Hello"

Thanks in advance.
__________________
"do you have to put stupid quotes in your messages?" - aaron
firefly is offline   Reply With Quote
Old Jun 5th, 2005, 11:25 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Investigate "strtok". Look also at strchr and strstr. Of course, you have to actually DEFINE for yourself how to decide that "firefly!firefly@somerandomhost.com" becomes merely "<firefly>".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 5th, 2005, 11:26 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I would personally just copy it to a new string. Loop up to the first ':', insert a '<', take everything up to the '!' and copy it into the string, insert "> ", loop up to " : " and then take the rest of the string.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 5th, 2005, 11:29 AM   #4
firefly
Newbie
 
Join Date: Jun 2005
Posts: 3
Rep Power: 0 firefly is on a distinguished road
Wow, just wat i wanted, thnx.
__________________
"do you have to put stupid quotes in your messages?" - aaron
firefly is offline   Reply With Quote
Old Jun 5th, 2005, 11:32 AM   #5
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
I am assuming those are e-mail addresses? If so, you might want to take a peek at RFC822, because the specification for e-mail addresses is pretty darned complex....
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty

Last edited by stevengs; Jun 5th, 2005 at 11:44 AM.
stevengs is offline   Reply With Quote
Old Jun 5th, 2005, 11:58 AM   #6
Nuticulus
Programmer
 
Nuticulus's Avatar
 
Join Date: May 2005
Location: England
Posts: 61
Rep Power: 4 Nuticulus is on a distinguished road
Actually, a RFC on the IRC protocol can be found here. It has some pseudo regular expressions there too to explain how it's formatted. Quite useful.

When I wrote my IRC engine, I found regexes invaluable. They were key in extracting data from strings quickly. You might want to look into pcre, which is basically an API for making and using perl-like regular expressions. It's quite good, and lots of high profile projects use it. There's a window port too.
Nuticulus is offline   Reply With Quote
Old Jun 5th, 2005, 12:24 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
After I posted that, I was thinking regex could come in handy - I just couldn't be bothered to come back and edit my post. If you want to use regular expressions, something like this might work:
:([^\s]+)![^:]*: ([^\r\n]*)
EDIT: is it me, or does that look like the most elaborate smiley ever?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 5th, 2005, 1:14 PM   #8
firefly
Newbie
 
Join Date: Jun 2005
Posts: 3
Rep Power: 0 firefly is on a distinguished road
I think i'll do the loop thing. But i will also look at regex's, they look interesting... not to mention complicating
__________________
"do you have to put stupid quotes in your messages?" - aaron
firefly is offline   Reply With Quote
Old Jun 5th, 2005, 1:14 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Ooble, I don't even want to imagine how that smiley got that expression on its face .

Regex is a wonderful tool. It also tends to be a resource hog. If the matching characteristics are reasonably simple, trudging down the string finding the delimiting characters is more effective. Finding delimiters and substrings are what strchr, strstr, and strtok do.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers

Last edited by DaWei; Jun 5th, 2005 at 1:17 PM.
DaWei is offline   Reply With Quote
Old Jun 5th, 2005, 1:42 PM   #10
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
Originally Posted by DaWei
..tends to be a resource hog...
imho, that was the most valuable line in this thread. I had noticed this before, but hadn't contributed it to the regex.. now I know better...
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC