Polymorphism Posted January 29, 2017 Share Posted January 29, 2017 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; } Quote Link to comment Share on other sites More sharing options...
Swizzbeat Posted January 29, 2017 Share Posted January 29, 2017 Overcomplicated to hell. A simple between : and ( parsing with trim would suffice. 1 Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted January 29, 2017 Author Share Posted January 29, 2017 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. Quote Link to comment Share on other sites More sharing options...
Explv Posted January 29, 2017 Share Posted January 29, 2017 (edited) 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, 2017 by Explv 1 Quote Link to comment Share on other sites More sharing options...