user1099280 user1099280 - 3 days ago 5
Java Question

Split complex string within a muliple sub string with same special character

I am trying to parse the string with semicolon with multiple substrings, here are the example

String temp = "SIM1_TM_4G3G2G_DE;ANY_RAT;TCNAME_Flight_Mode_Toggle;TIME_60;120;90;30"


Expected output required would be to display only values after the
TIME_
:

60
120
90
30


I have tried with the following code it did not do the following need

String[] args_val=temp.split(";");


log("STARTING THE LOOP");
for(int ix=0; ix<args_val.length;ix++)
{
log("args_val["+ix+"]-" +args_val[ix]);
//TIME is considered in seconds
if(args_val[ix].contains(TIME"))
{
log("args_val[ix] length -" +args_val[ix].length());
String sTime = args_val[ix].substring(args_val[ix].indexOf("TIME_") +5, args_val[ix].length());
log("print sTime-" +sTime);
}

}


Please do the needful.

Answer

Try this:

String output = temp.substring(temp.indexOf("TIME_") + 5)
                    .replaceAll(";", "");
Comments