String Splitting

Discussion in 'Plugin Development' started by np98765, Sep 9, 2012.

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

    np98765

    Hey there,

    I'm needing some help with string splitting. Let's say I have the following:

    1:2:3 4:5

    I want to split this first at the space, and then take part A (1:2:3) and part B (4:5) and split those at the colon. I've done this already.

    But now I have a question: How do I make these "optional"? If I want to make the entire part B 'optional', how would I do this (Part B is defining the enchantment and level)?

    Thanks!
     
  2. Offline

    skore87

    You would want to call the split method on the string with the delimiter as a space. Then you would split on the first string of the array. If the array was longer than 1, you would know to parse part B as well.

    And do remember that the delimiter is regex and therefore can be used to split on a pattern.
    http://pages.cs.wisc.edu/~hasti/cs302/examples/Parsing/parseString.html
     
Thread Status:
Not open for further replies.

Share This Page