Ignoring Cpas while Using replaceAll

Discussion in 'Plugin Development' started by scoutdrago3, Jul 28, 2013.

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

    scoutdrago3

    So toady is my first day at modding and i'm new(Of Course) so I was trying to make a NoCaps/NoBadWord plugin but It would take me years to make all the If Statements on every way that someone can say a bad word. So I tried to put the
    Code:
    equalsIgnoreCase()
    before the
    Code:
    replaceAll("Ball Ball Ball", "Ball BAll Other Ball")
    but it gave me a error. SO my question is:
    Can I use IgnoreCase with replaceAll? If so How? If not I need a gun. :p

    Thanks to everyone who read or is Reading this :)!
     
  2. Offline

    afistofirony

    scoutdrago3 You can try one of these:

    Code:
    message = message.toLowerCase().replaceAll("ick", "***");
    However, this is not practical since it removes all capital letters in the message. It also means you could get unwanted matches, like "sick" or "kick".

    You can try this, though:
    Code:
    String[] words = message.split(" ");
    for (String word : words) {
        if (word.equalsIgnoreCase("ick")) {
            // do stuff
            break;
        }
    }
    Quick note about the "break;" statement above: that ends the for-each loop so that the player doesn't get 5 messages if they say "ick ick ick ick ick".
     
  3. Offline

    Polaris29

    scoutdrago3
    Code:java
    1.  
    2. String s = "Banana banana Banana Banana";
    3. System.out.println(s.replaceAll("Banana banana", "Monkey"));
    4. // Above output is "Monkey Banana Banana"
    5. System.out.println(s.replaceAll("(?i)Banana banana", "Monkey"));
    6. // Above output is "Monkey Monkey"
    7.  


    That "(?i)" turns on case insensitivity for the remainder of the regular expression. Notice how it says remainder, so anything before the (?i) will be case sensitive
     
  4. Offline

    scoutdrago3

    Thanks everyone! One question to Polaris:
    Can I use the (?!) in any replaceAll() statements or just the ones that start with System.out.println("A Word Of Advice"); Ok well thanks everyone again for the feedback! All of you are awesome!
     
  5. Offline

    afistofirony

    scoutdrago3 replaceAll() is one of String's method, so you can use it anywhere a String is needed:

    Code:
    "An example".replaceAll("(?i)a", "b");
     
    String s = "An example";
    s.replaceAll("(?i)a", "b");
     
  6. Offline

    scoutdrago3

    Thanks everyone
    Btw I'm gonna make another post on a bigger question so please if you guys can help me out that would be Awesome!
     
Thread Status:
Not open for further replies.

Share This Page