Solved Get everything in an Array after 1.

Discussion in 'Plugin Development' started by Quidam, Feb 17, 2013.

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

    Quidam

    Hey!
    How do I get every argument in an Array after args[1]?
    I need to do this so I can use a whole message, rather than just the first word.
    Thanks! :D
     
  2. Offline

    Hoolean

    Do you mean join all of the args? Or all of the args except the first one?

    If you mean all of the args, then do: StringUtils.join(args, ' ');
     
  3. Offline

    zack6849

    StringBuilder sb = new StringBuilder();
    for(int I =1; I < args.length; I++){
    sb.append(args + " ");
    }
    String allargs = sb.toString().trim();
     
  4. Offline

    Quidam

    MrBluebear3
    Everything after the second one. Ex:
    /mastercommand set message

    zack6849
    Could you explain a bit, rather than throw code at me, please? :p
     
  5. Offline

    Hoolean

    Fixed it a bit :p
     
  6. Offline

    Quidam

    Could you explain it a bit?
    If I just use the code I won't understand it.
     
  7. Offline

    Hoolean

    OK here it is in psuedo code-ness:

    Creates an object - let's say it is this []
    The for loop then goes through everything in args after args[1], which is why it starts on 'i = 2'. It then gets the bit of args that is corresponding to the number that is 'i' args[2], args[3], args[4], etc until it reachs the end and with this bit of args is adds to the object that was created before (StringBuilder). So say args was "/me likes bacon very much" the object would end up being [very +much ]. The toString bit then turns the object into a String ('very much ') and the trim gets rid of the unneccesary space on the end ;)
     
  8. If you're gonna use StringBuilder then don't use the '+' because that translates into another new StringBuilder by the compiler, instead use:
    Code:
    sb.append(args[I]).append(" ");
     
    zack6849 likes this.
  9. Offline

    Quidam

    MrBluebear3 likes this.
Thread Status:
Not open for further replies.

Share This Page