![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 3
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jun 2005
Posts: 3
Rep Power: 0
![]() |
Wow, just wat i wanted, thnx.
__________________
"do you have to put stupid quotes in your messages?" - aaron |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: May 2005
Location: England
Posts: 61
Rep Power: 4
![]() |
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.
__________________
http://www.nuticulus.net/hackmysig/sig.PNG Give my site a chance, you know you want to ;-) Google will solve 99% of your problems. Including those with your sex life. Caution, may <strike>contain</strike> be nuts. |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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]*) |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jun 2005
Posts: 3
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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. |
|
|
|
|
|
#10 | |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Quote:
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|