Question

Got a Question:

How can i combine message.equalsIgnoreCase and message.startswith() ?

i.e:

if (message.startsWith("!spoiler")) {
    String name = sender;
    if (!name.equalsIgnoreCase(ownerchannel)){
        try {
            String spoiler = message.split("!spoiler ")[1];
            sendMessage(channel, "/timeout "+name+" 1");
            if(englishmode == true){
                sendMessage(channel, "Spoiler from "+name+" deleted. Click at 'message deleted' above to read it!");
            }else{
                sendMessage(channel, "Spoiler von "+name+" wurde zensiert. Wer diesen lesen möchte klickt einfach oben auf 'message deleted'.");
            }
        } catch (Exception e) {
        }
    }
}

in my code above, !spoiler xyz will trigger it but !Spoiler xyz wont. how can i combine it to ma tch startswith + ignorecase?

Was it helpful?

Solution

You could use toLowerCase

if (message.toLowerCase().startsWith("!spoiler")) {

OTHER TIPS

Convert (a copy of) the string to all lower-case, then just use .startsWith() with the lower-case version of what it's checking for.

split requires a regular expression. You would have to use the regular expression for the case you don't care about.

message.split("![Ss]poiler");

Use the following code to combine both:

if (message.startsWith("!spoiler") && !sender.equalsIgnoreCase(ownerchannel)) {
        String name = sender;
            try {
                String spoiler = message.split("!spoiler ")[1];
                sendMessage(channel, "/timeout "+name+" 1");
                if(englishmode == true){
                    sendMessage(channel, "Spoiler from "+name+" deleted. Click at 'message deleted' above to read it!");
                }else{
                    sendMessage(channel, "Spoiler von "+name+" wurde zensiert. Wer diesen lesen möchte klickt einfach oben auf 'message deleted'.");
                }
            } catch (Exception e) {
            }

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top