Jump to content

Replaceall


Recommended Posts

wie kann ich bei replaceall die groß und kleinschreibung ignorieren?

Das habe ich

	@EventHandler(priority = EventPriority.HIGHEST)
	public void OnChat(AsyncPlayerChatEvent e){
		String msg = e.getMessage();
		
		for(int i = 0; i <Main.blacklist.size(); i++){
			msg = msg.replaceAll(Main.blacklist.get(i), "§4ZENSIERT§r");
		}
		e.setMessage(msg);
	}

blacklist ist eine arraylist in der schimpfwörter in einen string gespeichert sind

Link to comment
Share on other sites

Hab mal ein kleines Programm geschrieben. 

public class MessageMod {
	private static  ArrayList<String> blacklist = new ArrayList<String>();
	public static void main(String args[]) {
		blacklist.add("assi");
		Chat();
	}
	
	public static void Chat(){
	String message = "Du bist ein dummer Assi";
	List<String> messageparts = Arrays.asList(message.split(" "));
	
	String newmessage = "";
	for(String part: messageparts){
		if(toreplace(part)){
			part = "**** ";
		}
		newmessage = newmessage+part+" ";
	}
	System.out.println(message);
	System.out.println(newmessage);
	}
	
private static boolean toreplace(String string){
		boolean out = false;
		
		for(String st : blacklist){
			if(string.toLowerCase().equals(st)){
				out = true;
			}
		}
		return out;
		
	}
	

}

Das wäre meine Herangehensweise an das Problem.

 

Freundliche Grüße

BloodSKreaper

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...
B
B