Please figure out the error

hi all,

heres a problem I can't it out can any one help me.

Its not printing the WieldValue5

the String here it should ignore "SXGI", "F"'s, and "E" and it should print ControlID1

WieldType1

WieldValue1

...

ControlID5

WieldType5

WieldValue5

its not printing "WieldValue5"

publicclass Example{

publicstaticvoid main(String[] args)throws Exception{

String strReq ="SXGIDFControlID1FWieldType1FWieldValue1F" +

"ControlID2FWieldType2FWieldValue2F" +

"ControlID3FWieldType3FWieldValue3F" +

"ControlID4FWieldType4FWieldValue4F" +

"ControlID5FWieldType5FWieldValue5E";

int iIndexF = strReq.indexOf("F");

String strTemp = strReq.substring(iIndexF + 1);

int iIndexE = -1;

while(-1 != iIndexF){

iIndexF = strTemp.indexOf("F");

if(-1 == iIndexF){

thrownew Exception("Error in ControlID");

}

String strControlID = strTemp.substring(0, iIndexF);

System.out.println(strControlID);

int iIndexFieldType = strTemp.indexOf("F", iIndexF + 1);

if(-1 == iIndexFieldType){

thrownew Exception("Error in FieldType");

}

String strFieldType = strTemp.substring(iIndexF + 1, iIndexFieldType);

System.out.println(strFieldType);

int iIndexFieldValue = strTemp.indexOf("F", iIndexFieldType + 1);

String strFieldValue;

if(-1 == iIndexFieldValue){

thrownew Exception("Error in FieldValue");

}

strFieldValue = strTemp.substring(iIndexFieldType + 1, iIndexFieldValue);

System.out.println(strFieldValue);

iIndexF = iIndexFieldValue;

if(-1 == iIndexF){

iIndexE = strTemp.indexOf("E", iIndexFieldType + 1);

if(-1 == iIndexE){

thrownew Exception("Error in FieldValue");

}

strFieldValue = strTemp.substring(iIndexFieldType + 1, iIndexE);

System.out.println(strFieldValue);

iIndexFieldType = iIndexE;

}

strTemp = strTemp.substring(iIndexFieldValue + 1);

System.out.println(strTemp);

}

}

}

null

null

[3696 byte] By [Inspiron123a] at [2007-10-3 3:28:08]
# 1

Perhaps you should take a step back. What is it you are trying to do? For example, what is "strReq" and how is it formatted? Are you trying to store multiple units of data in a single string and then parse that string so as to extract the data?

If so, it seems that the way you're going about doing it is rather complicated and will be difficult to maintain in the future. We may be able to suggest an easier approach.

tvynra at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...
# 2
hi its the one whole string i have to parse itthank you
Inspiron123a at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...
# 3
strip those characters first?
mchan0a at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...
# 4

Based on the information you've provided, here's a stripped down version:

String strReq = "SXGIDFControlID1FWieldType1FWieldValue1F" +

"ControlID2FWieldType2FWieldValue2F" +

"ControlID3FWieldType3FWieldValue3F" +

"ControlID4FWieldType4FWieldValue4F" +

"ControlID5FWieldType5FWieldValue5E";

intbeg= 0, end= 0;

while ( true ) {

beg = strReq.indexOf("F",beg);

end = strReq.indexOf("F",beg+1);

if (beg != -1) {

if ( end == -1) {

end = strReq.indexOf("E",beg+1);

if ( end == -1)

end = strReq.length();

}

System.out.println(strReq.substring(beg+1,end));

}

else

break;

beg = end;

}

abillconsla at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...
# 5
Thanks for the replywhat if i want to store in 3 array
Inspiron123a at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...
# 6
Sure, why not?
abillconsla at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...
# 7
Honestly, if your parsing problem isn't context-dependent and the parameters of the task permit you to do this, I would just use String.split. But perhaps you are not allowed to do so?
tvynra at 2007-7-14 21:21:41 > top of Java-index,Java Essentials,New To Java...