January 29, 20179 yr Takes a little bit of regex but it's simple to do. Instead of adding the item name to a list, in my loop() I do if valuableLootName !empty then force loot the one item, then resume normal function. String tmpLootName = ""; if (msg.contains("aluable drop")) { tmpLootName = msg.replace("<col=ef1020>", "").replace("</col>", "") .replaceFirst("(.{0,15})", "").replaceFirst("(\\d x)", "") .replaceFirst("\\(([^\\)]+)\\)", "").trim(); log("DROP MESSAGE: " + tmpLootName); valuableLootName = tmpLootName; }
January 29, 20179 yr Overcomplicated to hell. A simple between : and ( parsing with trim would suffice.
January 29, 20179 yr Author 13 hours ago, Swizzbeat said: Overcomplicated to hell. A simple between : and ( parsing with trim would suffice. Meh, looks overcomplicated to hell. You'd still have to parse out the quantity by going with substring and trim. I found it easier on my eyes to do it this way, and the speed difference is so little it's laughable. Now if we were doing like 20k of these in one go this would be done a little different.
January 29, 20179 yr 14 hours ago, Polymorphism said: Takes a little bit of regex but it's simple to do. Instead of adding the item name to a list, in my loop() I do if valuableLootName !empty then force loot the one item, then resume normal function. String tmpLootName = ""; if (msg.contains("aluable drop")) { tmpLootName = msg.replace("<col=ef1020>", "").replace("</col>", "") .replaceFirst("(.{0,15})", "").replaceFirst("(\\d x)", "") .replaceFirst("\\(([^\\)]+)\\)", "").trim(); log("DROP MESSAGE: " + tmpLootName); valuableLootName = tmpLootName; } 13 hours ago, Swizzbeat said: Overcomplicated to hell. A simple between : and ( parsing with trim would suffice. Agreed, this is over complicated. Either of these options would suffice: Where the message is: String lootMessage = "<col=ef1020>Valuable drop: Onyx (3,038,047 coins)</col>"; Matcher m = Pattern.compile(": (.+) \\(").matcher(lootMessage); if (m.find()) { String loot = m.group(1); } or String loot = lootMessage.substring(lootMessage.indexOf(": ") + 2, lootMessage.lastIndexOf(" (")); Edited January 29, 20179 yr by Explv
Create an account or sign in to comment