Get last args

Discussion in 'Plugin Development' started by Whatsfast, Jan 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Whatsfast

    Im tryingto make a msg command. How would I get the last args in what the user said like from args[3]+
     
  2. Offline

    skore87

    Code:
    StringBuilder sb = new StringBuilder();
     
    for (int i = 3; i < args.length; i++){
    sb.append(args[i]);
    if (i<args.length)
    sb.append(" ");
    }
     
    System.out.println(sb.toString());
     
  3. Offline

    adam753

    I may be mistaken but don't arrays have a length function/variable? So iteratively add each argument into a string, starting at 3 and ending at array.length.

    Edit: what this guy said^
    Well, a StringBuilder class seems a bit excessive. But yeah.
     
  4. Offline

    Whatsfast

    thanks.
     
  5. Offline

    Bench3

    Code:
    String lastArg = args[args.length-1];
    This would be much simpler?
     
  6. Offline

    RealDope

    He wants all the last arguments, not just the VERY last one.
     
  7. Offline

    skore87

    If you want to retain it in array format, you can use the subarray commands but the method i showed makes it into a message.
     
Thread Status:
Not open for further replies.

Share This Page