I've been getting an error on .replace on the end of the long string of code. Any ideas why? Code: if (CrateController.crateExist(j)) { str1 = SettingsManager.Messages.getString("success.removed").replace("[crate]", SettingsManager.Config.getString(new StringBuilder("crates.").append(j).append(".name").toString()) + " Crate").replace("[id]", j); paramCommandSender.sendMessage(C.getPrefix() + C.inColor(str1)); SettingsManager.Config.set("crates." + j, null); } else { str1 = SettingsManager.Messages.getString("error.crate-id-not-found"); paramCommandSender.sendMessage(C.getPrefix() + C.inColor(str1));
Uhhh, no, then you'd be using a regular expression that matches all of the characters in "crate" and replaces them. Bad news bears. You don't need to use a StringBuilder for something as simple as what you're doing. You can just do primitive String concatenation unless you're worried about thread-safety. Code: str1 = SettingsManager.Messages.getString("success.removed").replace("[crate]", SettingsManager.Config.getString("crates."+j+".name") + " Crate").replace("[id]", j); Additionally, it's hard to solve an error when you don't paste it or show us it.
.replaceAll("[crate]", crateName) doesn't replace all the characters in crate it replaces ALL of the [crate]'s inside a string to the crate name so you don't have to use .replace multiple times if there are multiple [crate]'s in the string
That's potentially the most ignorant thing I've heard. Look up the Java Documentation for the two methods, please. Replace: Yields: ----------------------------------------------------------------------------------- ReplaceAll: Yields: ^ Notice how the 'R' is left alone because it is not the same character as 'r'.