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
Post a Comment