Search This Blog

Saturday, January 1, 2011

tokenizing a string with unequal number of spaces between words.

Programmer Question

I am tryint to tokenize entries from a file. However I am not able to use the line.split("") option because of unequal number of spaces between files. I am copying a few lines from my file below:



"08-09-2010 21:21:46      00:22:7f:a6:9b:69                                 -79"
"08-09-2010 21:21:46 04:4f:aa:b4:49:49 -79"
"08-09-2010 21:21:46 04:4f:aa:31:4e:59 tikona 18002090044 -83"
"08-09-2010 21:21:46 00:22:7f:26:9b:69 tikona 18002090044 -74"
"08-09-2010 21:21:46 04:4f:aa:34:0d:c9 tikona 18002090044 -82"
"08-09-2010 21:21:46 04:4f:aa:71:4e:59 -85"
"08-09-2010 21:21:46 04:4f:aa:34:21:89 tikona 18002090044 -75"
"08-09-2010 21:21:46 04:4f:aa:34:49:49 tikona 18002090044 -77"
"08-09-2010 21:21:46 04:4f:aa:74:0d:c9 -85"
"08-09-2010 21:22:47 18 APs were seen
"


I need to access the first column (which is a datetime object) the second column (00:22....) and the last column (-79 etc). I have no trouble accessing the first and second columns, but not the last column. When I do a info=line.spilt(""), since the third column might or might no entries, I am not able to determine the token number.



How do i access the 4th column? Is there a way i can use info[i].contains(" -")?



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails