Get Integers from String

Discussion in 'Spigot Plugin Development' started by XelfeGamer, Jun 18, 2015.

  1. Hey guys im trying to make an Anti-Spam plugin and i make this but i don't know why it doesn't work
    My code:
    Code (Text):
    Integer cantidad = 0;
                for(int i = 0; i == event.getMessage().length(); i++) {
                    if(Character.isDigit(event.getMessage().charAt(i))) cantidad++;
                }
               
                for(int i = 0; i == event.getMessage().length(); i++) {
                    try {
                        Integer.parseInt(String.valueOf(event.getMessage().charAt(i)));
                        cantidad++;
                    } catch(Exception e) {
                       
                    }
                }
    What im doing wrong?

    Thanks in advance.
     
  2. sothatsit

    Patron

    Code (Text):

                for(int i = 0; i == event.getMessage().length(); i++) {
                    ...
                }
             
                for(int i = 0; i == event.getMessage().length(); i++) {
                    ...
                }
    The statement in your for loop is wrong, particularly:
    Code (Text):
    i == event.getMessage().length()
    Can you see whats wrong? Have a look and try to figure it out.
     
  3. Well, what part of it isn't working?
     
  4. I think that's correct
    It doesn't work for example: if the message is equals "Hey 12345" cantidad is 0 and it should be 5
     
  5. sothatsit

    Patron

    It isn't correct, thats what im telling you. Try searching up for loops to figure out what your doing wrong.
     
  6. Took me a little bit to see what sothatsit was talking about, but yes he is correct, there is something wrong with the loop.
     
  7. Thanks to both, now it works :)