Java find URL in string and create HTML link tag -


in string have result:

content = "hello world, visit link: www.stackoverflow.com"; 

or

content = "hello world, visit link: http://www.stackoverflow.com"; 

or

content = "hello world, visit link: http://stackoverflow.com"; 

now want find url in string , finaly create html link tag result:

htmlcontent = "hello world, visit link: <a href="http://stackoverflow.com">http://stackoverflow.com </a> "; 

how result?

htmlcontent = "hello world, visit link: <a href="[http://|www.] stackoverflow.com">[http://|www.]stackoverflow.com </a> "; 

you can try this:

string content = "hello world, visit link: www.stackoverflow.com";      string[] splitted = content.split(" ");     (int = 0; < splitted.length; i++) {         if ((splitted[i]).contains("www.")) { // use more statements                                                 // http:// etc..             system.out.println(splitted[i]); //just checking output             string link = "<a href=\"" + splitted[i] + "\">" + splitted[i] + "</a>";              system.out.println(link); //just checking output         }     } 

use \" in string write quotation marks inside string.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -