avatar
marking function

Ninh 1.7K 16th Jun, 2021

class Playground {
    public static void main(String[ ] args) {
        System.out.println(markText("oi doi oi De vai l de", "De"));
    }

    public static String markText(String text, String keyword){
        String output = "";
        String[] words = text.split("\\s+");
        for (int i = 0; i < words.length; i++) {
            if(words[i].equalsIgnoreCase(keyword)){
                output += "<mark>"+words[i]+"</mark> ";
            } else {
                output += words[i] + " ";
            }
        }
        return output.trim();
    }
}
Java
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data