Solved If config contains string ignore case

Discussion in 'Plugin Development' started by xGamingDudex, Oct 21, 2012.

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

    xGamingDudex

    Hi, is there a way to use the getConfig().Contains(StringPath); but ignore case.

    Config:
    Code:
    Test: hi
    testboolean: false
    how:
      are:
        you: bad
        you: good
    if i do:
    HTML:
    if(getConfig().contains("Test")){
    // Code
    }
    it will run the code, but if I do
    HTML:
    if(getConfig().contains("test")){
    // Code
    }
    it won't.

    Is there any way to run the code using "test"?
     
  2. Offline

    lol768

    Hmm, this should be something to be considered to be implemented in the Bukkit configuration API. However, there are some workarounds:
    • Go over each key in config and change it to lower case before comparing.
    • Get an arraylist of all the keys, change them all to lowercase then do a .contains("test")
    • Put a comment in the config file telling users to default to lowercase.
     
  3. Offline

    xGamingDudex

    Thanks, I had tried so long for check if the config contained the string that I had forgotten that I just could go through the keys manually =)

    For every one that bumps into the same problem here is how to check if the config contains a string and ignore case:
    HTML:
        public boolean configContains(String arg){
            boolean boo = false;
            ArrayList<String> keys = new ArrayList<String>();
            keys.addAll(getConfig().getKeys(false));
            for(int i = 0; i < keys.size(); i++){
                if(keys.get(i).equalsIgnoreCase(arg)){
                    boo = true;
                }
            }
            if(boo){
                return true;
            } else {
            return false;
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    xGamingDudex

    Can some one of the admins move this thread to resources?
     
  5. Offline

    iforgot290

    Why not just create your own thread there? :p
     
Thread Status:
Not open for further replies.

Share This Page