Java, android Scanner 简单的使用


Scanner sc = new Scanner(“remote_action,speed=100,time=10000”);


sc.useDelimiter("(,|=)");

sc.next();  // remote_action
while(sc.hasNext())
{

String item = sc.next();

if(!sc.hasNext())
break;
if("speed".equals(item))
{
int speed = sc.nextInt();
if(speed >0)
{
this.nSpeed = speed;
}
continue;
}
if("time".equals(item))
{
int time = sc.nextInt();
if(time > 0)
{
this.nTimeslice = time;
}
continue;
}
}
sc.close();

你可能感兴趣的:(Android)