为什么此 StringTokenizer 在第二次之后无法正确标记?
我想使用 StringTokenizer 为每个匹配 agent>
的字符串解析以下内容。我尝试使用这样的代码。我哪里错了?
StringTokenizer stringtokenizer=new StringTokenize(hari,"agent>");
while(stringtokenizer.hasMoreTokens())
{
String token = stringtokenizer.nextToken();
System.out.println("output ="+token);
}
它只正确标记两次,然后就响应不规则...... 我的意思是第一次
output =ACT-USER::USER_1:AU01::******;
SIMULATOR 09-11-17 09:37:01
M AU01 COMPLD
;
第二次:
output =RTRV-HDR:::RH01;
SIMULATOR 09-11-17 09:37:01
M RH01 COMPLD
;
第三次:
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>
I want to parse the following using StringTokenizer for every string matching agent>
. I tried it using the code like this. Where I am going wrong?
StringTokenizer stringtokenizer=new StringTokenize(hari,"agent>");
while(stringtokenizer.hasMoreTokens())
{
String token = stringtokenizer.nextToken();
System.out.println("output ="+token);
}
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你没有读过API。
StringTokenizer
不接受字符串作为单个分隔符。它接受一个字符串,其中字符串中的每个字符都被视为一个字符分隔符。尝试使用 String.split(...);
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(...);
试试这个,
Try this,