Hi all,
I have a scenario, where i have to iterate a string and have to return the third value.
For an example i have sting which is a Number sequence . "LAB-000052-5".
I split this string and then i use list iterator to get the third position.
Please note that if my string has "LAB-000052", it should return default to 1.
Kindly refer my below code. And please help me to achieve this.
int s=1,i,j;
str defaultno,t;
List list = new List(Types::String);
ListIterator it;
defaultno = int2str(s);
tabA= element.args().record();
list = strSplit("LAB-000052-5","-");// I will also pass "LAB-000052"
it = new ListIterator(list);
while(it.more())
{
it.next();
i++;
if (i == 2)// it will loop 3 times since my string is splitted into 3. so i get the value of 2 here.
{
defaultno = it.value();// which is 5.
}
}
return defaultno;
Now if pass only "LAB-000052", the if condition passes the end value to the defaultno.
in the above line if pass "LAB-000052", i need to return 1 to the defaultno.
Please help.
Thanks in advance,.