Solved Get integer in a string

Discussion in 'Plugin Development' started by slater96, Aug 16, 2013.

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

    slater96

    Hello, I need to get the integer in a string e.g.

    String test = "Example 10";

    How can I get the integer from that string? Thanks
     
  2. Offline

    Axe2760

    Use Integer.parseInt(string);

    Not sure how to get just the integer from that string, maybe test.split(" "); ?
     
  3. Offline

    Techy4198

    int myNumber = Integer.parseInt(test.split(" ").get(1));
    but this relies on only having one space before the number; having 'Example blarghhhh 1' and 'Example 1' will not work. basically replace the 1 in .get(1) with however many spaces you have before the number. if the number of spaces might change, then there is probably no simple way to do this. this is how I do it, anyway.
     
    slater96 likes this.
Thread Status:
Not open for further replies.

Share This Page