Solved EqualsIgnoreCase List?

Discussion in 'Plugin Help/Development/Requests' started by Corndogoz, Apr 12, 2015.

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

    Corndogoz

    hai guys, so basicly all i need is my plugin to take a string, and turn it into a list of every combination of caps and lower case possible, here is an example: "Hello" would be "hello" "HELLO" "Hello" "hEllo" "heLlo" "helLo" "hellO" "Hello"
    "HEllo" "heLLo" "helLO" u get the point is this even possible? idk, but if it is, please tell me how! i have tried many ways and epicly failed, so i currently have no code
     
  2. Offline

    TGRHavoc

    @Corndogoz
    Yes it's possible. It's fairly basic Java. Just use "myString.equalsIgnoreCase("SomeString")" this will check that the string with the name "myString" matches "SomeString" ignoring the case of either string.
     
  3. Offline

    Corndogoz

    thts easy, i do tht all the time, but that returns a boolean, that is what i need, but their is a reason i cant do it, i need a list of all the combinations
     
  4. Offline

    TGRHavoc

    @Corndogoz
    May I ask why you "need" this list?
    You may be thinking of a solution to a problem when there is another (potentially better) solution at your disposal.
     
  5. Offline

    Corndogoz

    ok, i will give u my code and u will see
    Code:
    for (int i = 0; i < getConfig().getList("Faces").size(); i++) {
    
                if (line.contains(String.valueOf(getConfig().getList("Faces").get(i)))) {
                    for (Object s : getConfig().getList("Faces")) {
                        face = String.valueOf(s);
                        if (getConfig().getList("FacesWPerms").contains(face)) {
                            if (!p.hasPermission("smileys." + face)) {
                                return line;
                            } else {
                                line = line.replace(face, getConfig().getString(face));
                                if (i > getConfig().getList("Faces").size()) {
                                    return line;
                                }
    
                            }
                        } else {
                            line = line.replace(face, getConfig().getString(face));
                            if (i > getConfig().getList("Faces").size()) {
                                return line;
                            }
                        }
                    }
                }
            }
    however, i dont need it to matter what case the string is
     
  6. Offline

    TGRHavoc

    @Corndogoz
    Assuming you're referring to the line "line.contains(someString)" then you could create a method.
    Something along the lines of:
    Code:
    public boolean listContainsStringIgnoringCase ( List<String> listToCheck, String stringToCheck ){
        for (String s: listToCheck){//For each of the strings stored
            if (s.equalsIgnoreCase(stringToCheck)) //Check the current string matches the string given (Ignoring case)
                return true; //Found a string in the list that matches the string given
        }
        return false; // List doesn't contain this string
    }
     
  7. Offline

    Corndogoz

    ya ya ya, ik this, but thats not the problem, when i do string.replace i need it to be for example string.replace(ignorecase("blahblahblah"), "blahblahblah");
     
  8. Offline

    TGRHavoc

    @Corndogoz
    Couldn't you just convert the original string to lowercase then replace your desired string?
     
  9. Offline

    Corndogoz

    no, because in the configuration, it might not all be lowercase
     
  10. Offline

    Yaron_1231

    try using String.replaceAll("(?i)"+String, getConfig()....);
     
  11. Offline

    Corndogoz

    what makes that ignore the case?
     
  12. Offline

    I Al Istannen

  13. Offline

    Corndogoz

    ok, thank u

    does it still work if u use it in .replace and not .replaceAll?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  14. Offline

    I Al Istannen

    @Corndogoz It works in every method that accepts Pattern. .replace doesnt. .replaceFirst uses regex, just like .replaceAll
     
  15. Offline

    Corndogoz

    kk, thx very much

    .replaceAll actually gives me plugin an error
     
    Last edited by a moderator: Apr 14, 2015
  16. Offline

    nverdier

  17. Offline

    Corndogoz

    ok everyone, my code is now:
    Code:
    public String changeToCorrect(Player p, String line) {
            for (int i = 0; i < getConfig().getList("Faces").size(); i++) {
                for (Object s : getConfig().getList("Faces")) {
                    face = String.valueOf(s);
                    if (getConfig().getList("FacesWPerms").contains(face)) {
                        if (!p.hasPermission("smileys." + face)) {
    
                        } else {
                            line = line.replaceAll("(?i)" + face, getConfig().getString(face));
                            if (i > getConfig().getList("Faces").size()) {
                                return line;
                            }
    
                        }
                    } else {
                       
                        line = line.replaceAll(face, getConfig().getString(face));
                        if (i > getConfig().getList("Faces").size()) {
                            return line;
                        }
                    }
                }
    
            }
    
            return line;
        }
     
Thread Status:
Not open for further replies.

Share This Page