xyz said:
I have a string
16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168
i have so many of such lines
for example lets say for the above string
16:23:18.659343 -- time
131.188.37.230 -- srcaddress
22 --srcport
131.188.37.59 --destaddress
1398 --destport
tcp --protocol
168 --size
i need to split this string such that i need to get all these
parameters....
thank you for any help
Well, look closely at the string you have presented and you will see
that all unrelated elements are separated by a space. First you have
the time field with three components, each separated by the ':'
character. The total field length is 15 characters. Then comes the
combination of source address and port, this time the components are
separated by a '.' character and the last component specifies the
source port. The destination address and port field follows the same
organisation. The comes the protocol field which is usually TCP or
perhaps UDP. The remaining component specifies the payload size.
So to split this string to get the components in the manner you
indicate, splice the string at each whitespace character. Then for
second and third substrings that you so get split of all characters
that follow the fourth '.' character.
Note that the above method is totally hackish and fragile. If you want a
robust solution then you must study the protocol involved in detail and
either construct your own parser for it or use one of the many free
ones available on the Net.
Now try doing it and if the code is in C you can post here for further
help and comments. If you attempt it in C++ then post to comp.lang.c++.