This is my 2nd. tutorial i hope you like it: Splitting is when you have e.g this String: "Hello my name is FisheyLP", and you want to split it on each whitespace. Code:Java //The StringString bla = "Hello my name is FisheyLP"; //Now we split it on each whitespace (you can too use e.g this or other symbols ---> _).String[] splittedBla = bla.split(" "); //the stringlist contains now the following words: Hello, my, name, is and FisheyLP. //Lets say i want to get the word name out of the stringlist.String name = splittedBla[2]; //Its similar to the args[] in the method onCommand.//Hello = splittedBla[0]//my = splittedBla[1]//name = splittedBla[2]//is = splittedBla[3]//FisheyLP = splittedBla[4] *Hm... I want to make a /give command with metadata but dont know how* Try it like this: Code:Java if(commandLabel.equalsIgnoreCase("give")){if(args.length<1){return false;}else{try{String[] idAndData = args[0].split(":");int id = Integer.parseInt(idAndData[0]);int meta = Integer.parseInt(idAndData[1]);ItemStack item = new ItemStack(id, 64, (short) 1, (byte) data); //id=ItemID, (short) 1 = itemDamage, (byte) data = the number behind the :p.getInventory().addItem(item);}catch(Exception e){ }}}
Not2EXceL Although true, someone who has to look up how to split strings is in no position to learn regex.
But they should know that it takes regex, otherwise they'll be confused when they accidentally input a regex function and it doesn't work how they thought it would.
You should at least mention it, or suggest a different API that doesn't use regular expressions at all (here using Guava, which is built-in into Bukkit): Code:java List<String> split = Splitter.on(" ").splitToList("This is a test."); Alternatively, you can escape the delimiter: Code:java "A string".split(Pattern.quote(" "))