Σάββατο 26 Νοεμβρίου 2011

Java Code:Underline keyword in sentence

1:    public String markWord(String sentence, String word) {  
2: int lastFound = -1;
3: while ((lastFound = sentence.toLowerCase().indexOf(word, lastFound)) > -1) {
4: String prefix=sentence.substring(0, lastFound) + "<u><b>";
5: String _word= sentence.substring(lastFound,lastFound+ word.length());
6: String suffix="</b></u>"
7: + sentence.substring(lastFound + word.length(), sentence.length());
8: sentence = prefix+_word+suffix;
9: lastFound+="<u><b></b></u>".length();
10: }
11: return sentence;
12: }

LinkWithin

Blog Widget by LinkWithin

Mobile edition