Loop through the args?

Discussion in 'Plugin Development' started by Alex_Cboy, Apr 10, 2014.

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

    Alex_Cboy

    Hello guys,
    Are you experienced enough to help me on this:
    I want to loop throu the args[1]++ not args[0]++
    example: /ban args[0] args[1] blah blah blah
    Args[0] = player's name
    Args[1] and all other args will be the reason.
    Thanks!
     
  2. Offline

    Wolfey

    Are you trying to loop through all the args? If so, do this:
    Code:java
    1. String reason = "";
    2. for(int i = 1; i < args.length; i++) {
    3. reason += s[ i ] + " ";
    4. }
    5. // variable reason will be the reason
     
  3. Offline

    Alex_Cboy

    No i want to loop throu the Args[1] and all other except args[0]
     
  4. Offline

    Wolfey

    Alex_Cboy That's what I just showed you.... if you notice I'm starting loop at 1.
     
  5. Offline

    mazentheamazin

    Alex_Cboy
    Well, his loop is doing that, starting at args[1] and getting higher until it reaches the max length. This is one way to do it, however I like to use StringBuilder
    Code:java
    1. StringBuilder sb = new StringBuilder(); //Creating a new instance of StringBuilder
    2. for(int i = 1; i < args.length; i++) { //Basic for loop, going through the arguments starting from 1
    3. sb.append(args[i]); //Adds the argument into the StringBuilder
    4. sb.append(" "); //Adding a space into the StringBuilder
    5. }
    6.  
    7. String reason = sb.toString(); [/i]
     
Thread Status:
Not open for further replies.

Share This Page