How to get int using a string containing int

Discussion in 'Plugin Development' started by i3ick, Sep 10, 2015.

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

    i3ick

    So I need to get the value of "level1"
    int level1 = 500;

    What I do is try to make a string that would be "level1" and then return the int.
    I'm not sure how to actually go about this though:

    Code:
      public int leftToNextRank(){
            int nextlevel = getLevel() + 1;
            String getlevelpoints = ("level" + Integer.toString(nextlevel));
            int points = this.getlevelpoints;
        }
    
    
        int level1 = 500;
     
  2. Offline

    RainoBoy97

    Remove all the text using String#subtring or a Regex then use Integer#parseInt
     
  3. Offline

    i3ick

    @RainoBoy97 No, i'm not trying to take apart "level1" and get 1, but rather I need the vaule of level1, which is 500.
     
  4. Offline

    mythbusterma

    @i3ick

    Perhaps you want a Map that associates Strings to Integers?
     
    i3ick likes this.
  5. Offline

    DoggyCode™

    String str = "10";

    int i = Integer.parseInt(str);

    ?
     
  6. Offline

    Petersoj

    Code:
    String.valueOf(nextLevel);
    
     
  7. Offline

    MCnumi

    ^^^^^^^^^^^^^^

    This is how you do it.
     
  8. Offline

    teej107

    I like this idea.
     
Thread Status:
Not open for further replies.

Share This Page