views:

146

answers:

1

Hi all, i want to parse the following using StringTokenizer for every string matching "agent>". I tried it using the code like this. Please let me know where i am going wrong.

StringTokenizer stringtokenizer=new StringTokenize(hari,"agent>");

while(stringtokenizer.hasMoreTokens())
{
    String token = stringtokenizer.nextToken();
    System.out.println("output ="+token);
}

but it is tokenizing properly only for two times and then it is responding irregularly.... I mean for first time

output =ACT-USER::USER_1:AU01::**;

SIMULATOR 09-11-17 09:37:01 M AU01 COMPLD ; Second time: output =RTRV-HDR:::RH01;

SIMULATOR 09-11-17 09:37:01 M RH01 COMPLD ; Third time: output =RTRV-EQPT::ALL:RE01;

SIMULATOR 09-11-17 09:37:02 M RE01 DENY SROF /S output =us, R output =qu output =s output =d Op output =r output =io output = F output =il output =d/ ;

ACT-USER::USER_1:AU01::**;

SIMULATOR 09-11-17 09:37:01 M AU01 COMPLD ; agent>RTRV-HDR:::RH01;

SIMULATOR 09-11-17 09:37:01 M RH01 COMPLD ; agent>RTRV-EQPT::ALL:RE01;

SIMULATOR 09-11-17 09:37:02 M RE01 DENY SROF /Status, Requested Operation Failed/ ; agent>RTRV-ALM-EQPT::ALL:RA01;

SIMULATOR 09-11-17 09:37:03 M RA01 DENY SROF /Status, Requested Operation Failed/ ; agent>RTRV-ALM-EQPT::ALL:RA02::MJ,;

SIMULATOR 09-11-17 09:37:03 M RA02 DENY SROF /Status, Requested Operation Failed/ ; agent>RTRV-ALM-EQPT::ALL:RA03::MN,;

SIMULATOR 09-11-17 09:37:04 M RA03 DENY SROF /Status, Requested Operation Failed/ ; agent>RTRV-ALM-EQPT::ALL:RA04::MN,T-LASERCURR-1-HIGH;

SIMULATOR 09-11-17 09:37:04 M RA04 DENY SROF /Status, Requested Operation Failed/ ; agent>RTRV-PM-EQPT::ALL:RP01;

SIMULATOR 09-11-17 09:37:05 M RP01 DENY SROF /Status, Requested Operation Failed/ ; agent>INIT-SYS::SLOT-1-1-2:IS01::1;

SIMULATOR 09-11-17 09:37:05 M IS01 COMPLD ; agent>CANC-USER::USER_1:CU01;

SIMULATOR 09-11-17 09:37:06 M CU01 DENY IIAC /Invalid Access Identifier/ ; agent>

+3  A: 

Please let me know where i am going wrong.

You didn't read the API. StringTokenizer does not accept a string as a single delimiter. It accepts a string where each character in the string is treated as a one character delimiter.

Try using String.split(...);

camickr
thanks for telling me that it takes each character of a string as delimiter.....really thanks alot