String Searching

Discussion in 'Plugin Development' started by gustebeast, Apr 7, 2014.

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


    I was wondering what the best way to do this would be. Currently I am storing a series of reports in the forum of an array list. I then save the arraylist to a config. What I am currently trying to do is extract the data from a string.
    1 | ChewyzABaus | wild(-85,10,-14) | 04/06/14

    There is an example of a report that would be saved in the config. Here is the general format.
    <number> | <player-name> | <world>(<int>,<int>,<int>) | <date>

    I want the command "/report tp <player> <id>" which will teleport to the coordinates of a specific players report. So far I have it set up to find the given String using the <player> and <id>. Now all I need to do is extract the world name and coordinates.

    // header //
    String report = "1 | ChewyzABaus | wild(-85,10,-14) | 04/06/14"
    String world = "";
    String coordinates = ""

    Could you post a chunk of code that would set the world string to "wild" and set the coordinates string to "-85 10 -14"?
  2. Offline


    Kind of messy looking, but it works.

    1. String s = "1 | ChewyzABaus | wild(-85,10,-14) | 04/06/14";
    2. String world = s.split("\\|")[2].split("\\(")[0].trim();
    3. String coords = s.split("\\|")[2].split("\\(")[1].replaceAll("[()]", "");
Thread Status:
Not open for further replies.

Share This Page