string parsing

BlitzMax Forums/BlitzMax Programming/string parsing

I have a string that looks like the following:
Jul 29 17:44:20 mail httpd: Possible outgoing spam: by USERNAME (Domain.net) at 000.000.000.000 on 07/29/2007 22:44:20%: Total 200 recipients (TO: ) (CC: ) (BCC: *@hotmail.com, *@hotmail.com,*@..., *@hotmail.com, *@hotmail.com, *@hotmail.com


How can i go about reading that entire string and only extracting the Username part?

Is username always surrounded by the "by " and the "(Domain.net)" ?

You could instr the position of "by " and "(Domain". Based on the positions you get you will know exactly on which position the username starts, and how long it is. The rest is a matter of slicing I guess..

use a regular expression.

or... find "spam: by" find the next "(" and trim the bit inbetween.

Another option: if the username is always the n-th word, you could use a function that returns the n-th space-seperated slice from this string..

yeah none of that changes so I could search between by and (Domain)

as per what CS_TBL said...
Local in:String = "Jul 29 17:44:20 mail httpd: Possible outgoing spam: by USERNAME (Domain.net) at 000.000.000.000 on 07/29/2007 22:44:20%: Total 200 recipients (TO: ) (CC: ) (BCC: *@hotmail.com, *@hotmail.com,*@..., *@hotmail.com, *@hotmail.com, *@hotmail.com"
Local user:String = in.split(" ")[9]
Print user


There might be a problem with usernames that have spaces tho.. :P

its ok usernames cannot have spaces :)...thanks dmaz

whats .split()?

It's apparently a new method added without being documented. Guess I can ditch my SplitString function now.

Its a funcitonality of the string class like join as well.
Have been added during 1.24 and were mentioned a few times by mark himself.

oh