Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

generating html links from plain text

843838Jan 22 2007 — edited Feb 10 2007
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2007
Added on Jan 22 2007
12 comments
161 views