Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

java/jsp String manipulation problem

Thread view: 
questionmarc420@msn.com - 18 Jan 2006 20:16 GMT
Hi,
i have large paragraphs in form of Strings. and i need to iterate
through it and change all links into hyperlinks
this is what i used to format the text into readable paragraphs.

String data_body      =      data.getBody();
data_body = data_body.replaceAll("\n\n","<p>");

now iw ould like to know if anyone knows of a way i can replace all
www.blablahs.com wiht working <A href>www.blahblahs.com</a>

thanks
morc
javabuddha@gmail.com - 18 Jan 2006 20:41 GMT
Sounds like you need a HTMLEncode function, you should take
a look at:

http://www.suckingfish.com/view.do?crumb_id=dsid_1116

If you are just interested in adding the HREF link, then look at
the last line in that function.

str = str.replaceAll("((https?|ftp)://|mailto:)[^\\s<]+", "<A
HREF=\"$0\">$0</a>");

Good luck,

Matt
questionmarc420@msn.com - 18 Jan 2006 21:10 GMT
hey thanks this worked.  another quick question though:
how would make the link open in a new window?

thanks again
morc

> Sounds like you need a HTMLEncode function, you should take
> a look at:
[quoted text clipped - 10 lines]
>
> Matt
javabuddha@gmail.com - 18 Jan 2006 22:35 GMT
This is more of a javascript question actually, but take a look at:

http://www.devguru.com/Technologies/ecmascript/quickref/win_open.html

Good luck,

Matt

> hey thanks this worked.  another quick question though:
> how would make the link open in a new window?
>
> thanks again
> morc
steen - 19 Jan 2006 08:09 GMT
> hey thanks this worked.  another quick question though:
> how would make the link open in a new window?
>
> thanks again
> morc

Well the easy answer would be to simple extend the regular expression
like so:
str = str.replaceAll("((https?|ftp)://|mailto:)[^\\s<]+", "<A
TARGET=\"_new\" HREF=\"$0\">$0</a>");

/Steen
questionmarc420@msn.com - 19 Jan 2006 15:01 GMT
thanks eveyrthing worked.
but i ran into a little problem, i was wondering if anyone knew waht i
should do.

lets say the text is   "(www.blahblah.com)"
the code will include the ")" at the end of the string. Anyone know a
way around this?

thanks
morc


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.