Solved Getting a whole number from a string list.

Discussion in 'Plugin Development' started by ItsComits, Oct 13, 2017.

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

    ItsComits

    Hello, I have recently come across a problem while getting a number from a list. The issue is if I check for the number 1 I get number 10. Is there any way I can differentiate between them?
     
  2. Offline

    baighxansgaming

  3. Offline

    ItsComits

    @baighxansgaming All I have tried is looping through the string list and then checking each string with .contains("some int")
     
  4. Offline

    Zombie_Striker

    @ItsComits
    If it is specifically for numbers, just check if the value equals 1.

    If this does not answer your problem, can you explain what exactly are you trying to achieve?
     
  5. Offline

    ItsComits

    @Zombie_Striker What I am trying to do is get a string from the string list which includes numbers and other characters. I am trying to check if the number is equal to another number from a variable within my class using .contains. But this seems to not work as when I check for the nunber 1. I get 10, 11 etc
     
  6. Offline

    Iran

    If you are using the #contains() method it will return anything that has the character '1' in it, so you would probably have to do #equals().
     
  7. Offline

    ItsComits

    @baighxansgaming @Zombie_Striker @Iran The problem is not solved. I cannot do .equals() as this string contains more than just integers. The question is. How do I collect all of the integers within the string? from here I will use the .equals() to get an accurate result hopefully. :)
     
  8. Offline

    Zombie_Striker

    @ItsComits
    This looks like something where Regex is needed. Basically, what you want to do is create a pattern that check for the numbers and, using groups, find the substring that contains only the numbers.
     
  9. Offline

    Caderape2

    @ItsComits If the string follow a format, like class1, class2, class10 etc.. you can split 'class' for get the number. Otherwise, use regex.
     
  10. Offline

    ItsComits

    @Zombie_Striker I have got the issue solved. I did use Regex but forgot to remove the colour codes from the string which got me the wrong outcome. (ChatColor.stripColour). If you want to collect all numbers in a string use the regex \\D+. Thanks for the help. :D
     
Thread Status:
Not open for further replies.

Share This Page