0

I have an app and I want to have it take CMD's but its a 3 part CMD.

for example "1307%launchApp%n/a".

that's a 3 part cmd pass%cmd%additionalInfo split with %'s

how would i take that and store it in 3 different Strings?

String Pass;
String CMD;
String AdditionalInfo;

I do be leave to use a For Loop, but I would like to know how to implant it and why it works so that i could use it in different projects

THANK YOU!!

let me know if you need a better explanation or more info

jason flanagan
  • 117
  • 1
  • 1
  • 9

3 Answers3

2

You do not need to use a for loop as you can us inbuilt method split as:

 String sample = "1307%launchApp%n/a";
    String[] result = sample.split("%");
    String pass = result[0];
    String cmd = result[1];
    String additionalInfo = result[2];
    System.out.println("pass: " + pass + " CMD: " + cmd + " Addtional Info: " + additionalInfo);

It prints:

pass: 1307 CMD: launchApp Addtional Info: n/a

0

You can use this to split it

String string = "1307%launchApp%n/a";
String[] parts = string.split("%");
Hardik Patel
  • 212
  • 2
  • 15
0

I dont think you need for loop. Try,

String commandString = "pass%cmd%additionalInfo";
String[] commands = commandString.split("%");
String firstCommand = commands[0];
....
subhash
  • 2,689
  • 18
  • 13