How can I scan a text (a String) and add links when a word is an URL?
I tried the following which works but it's too slow:
String text = rs.getString("text");
text2scan=text.split("[\n ]")
for(int i = 0; i < text2scan.length; i++){
String replacement = null;
String word = text2scan;
log.info(word);
if(word.indexOf(".com")!=-1){
replacement="<a href=\""+word+"\">"+word+"</a>";
text=text.replaceAll(word, replacement);
text=text.replaceAll("www","http://www");
text=text.replaceAll("http://http://","http://");
text=text.replaceAll(">http://",">");
}
}
Isn't this already implemented somewhere?
Thanks
Niklas