String Splitting

Discussion in 'Plugin Development' started by np98765, Aug 27, 2012.

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

    np98765

    So, I've searched around this forum a bit, in an attempt to find how to split a string this complicatedly...

    Basically, I can get it from the config, but I need to be able to get the item ID, amount, durability, and enchantment from the config.

    The format I was planning on using was id:amount:durability:enchantment. So, 276:1:50:3 would give the the user 1 iron sword at durability 50 with enchantment "3" (whatever that happens to be).

    It'd be nice to use different characters (@, |), but I think that will complicate things. (i.e. id:amount@durability|enchantment).

    Could anyone give me an example of how I'd split this into 4 parts? Thanks!
     
    hawkfalcon likes this.
  2. Offline

    Barinade

    String[] s = string.split(":");

    Edit:

    String string = "1:2:3:4";
    String[] s = string.split(":");

    s[0] would be "1", s[1] would be "2", s[2] would be "3", s[3] would be "4"
     
  3. Offline

    np98765

    I got that part so far. Kind of wondering what I'd do after that. :p The string splits... And then...
     
    hawkfalcon likes this.
  4. Offline

    Barinade

    Are you trying to convert them to int?
     
  5. Offline

    np98765

    Yeah, I have to parse them... But that 's'. Is that representing the split string; how do I grab the 'parts'? I'd assume it's something like [2]..
     
  6. Offline

    Barinade

    Read my post, I edited it, sorry
     
  7. Offline

    travja

    You would use s[0] for the first number s[1] for the next, and so on, then you would do int item = Integet.parseInteger(s[0]); and go through them.
     
  8. Offline

    np98765

    Ah, yes! Awesome guys, thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page