Reputation: 371
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?
Upvotes: 3
Views: 3129
Reputation: 159844
You could use toLowerCase
if (message.toLowerCase().startsWith("!spoiler")) {
Upvotes: 5
Reputation: 1
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) {
}
}
Upvotes: 0
Reputation: 106460
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");
Upvotes: 0
Reputation: 8145
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.
Upvotes: 0