string parsing

BlitzMax Forums/BlitzMax Programming/string parsing

ckob(Posted 2007) [#1]
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?


CS_TBL(Posted 2007) [#2]
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..


Brucey(Posted 2007) [#3]
use a regular expression.

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


CS_TBL(Posted 2007) [#4]
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..


ckob(Posted 2007) [#5]
yeah none of that changes so I could search between by and (Domain)


dmaz(Posted 2007) [#6]
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



CS_TBL(Posted 2007) [#7]
There might be a problem with usernames that have spaces tho.. :P


ckob(Posted 2007) [#8]
its ok usernames cannot have spaces :)...thanks dmaz


ckob(Posted 2007) [#9]
whats .split()?


N(Posted 2007) [#10]
It's apparently a new method added without being documented. Guess I can ditch my SplitString function now.


Dreamora(Posted 2007) [#11]
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.


ckob(Posted 2007) [#12]
oh