#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155

    Searching Strings


    I need some help determining what, in the data my socket is receiving, is a username and what is a message. For example, my bot may receive something like, 1002 JOIN TyRaNiZe 0000 [SEXP]. 1002 is just the 4 numbers that represents JOIN, JOIN is obviously just there to remind you that the user is joining, TyRaNiZe is the username, 0000 is pointless to show, and [SEXP] is the client. Now for when a user talks, it will show something such as, 1005 TALK CleanSlateBot 000 "Hello."
    This is the same as the JOIN, CleanSlateBot would be the username and the message would be what's in the quotes. Can anyone show me some code that pulls out what is a user and what is a message?

    Update: I figured it out, I used find().
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Bay area
    Posts
    9
    Rep Power
    0
    You used find()? So you know the username ahead of time?

    I was going to suggest username = in_string.split()[2]
    if they're always in that order, and separated by a space....
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    I used find() to know which part othe string was the username/message.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I'd probably start by splitting the data at the first n white spaces. This will make it easier to check which elements are what. This way you can check if part 1 is... JOIN.

    I don't really know what data means what to battle.net of course but in theory: If part 1 is JOIN then part 2 has to be the userName. Or thats the general idea.

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Well here's what I did. If the data contained TALK, here was my code, d is the data.
    Code:
                elif d[5:9] == 'TALK':
                    username = d[10:d.find('"')-6]
                    user = username
                    message = d[d.find('"')+1:-1]
                    msg = message
                    event_talk(user, msg)
    This worked just fine, so far I've gotten absolutely no errors.

IMN logo majestic logo threadwatch logo seochat tools logo