-1

My String is like

String body = "GH 1234 RING 5";

I want to extract the number 1234, RING and last 5 into separate variables and want to compare each of those values..It will be like.. pass = 1234, cmnd = RING and duration = 5 like this.. Please help me to figure out how to achieve this. Im doing like

String body="GH 1234 RING";
String pass=bodypass = body.replaceAll("[^0-9]", "");

to get the 1234 in it.But i cant find how to retrieve RING and 5.

1 Answers1

1

Do this

String body = "GH 1234 RING 5";
String[] splited = body.split("\\s+");

Now this will be the result

splited[0] = GH
splited[1] = 1234
splited[2] = RING
splited[3] = 5
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57