File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Replacing substrings like ./ and ../ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Replacing substrings like ./ and ../" Watch "Replacing substrings like ./ and ../" New topic
Author

Replacing substrings like ./ and ../

Mahoney Futhark
Greenhorn

Joined: Nov 15, 2004
Posts: 5
I'm building a simple spider, but I am stuck right now as I can't format URL's the right way. Some websites uses relative addressing in their links like

href="./i_am_going_to_mess_with_your_spider.htm"

or

href="../i_am_going_to_mess_with_your_spider_too.htm"

I have translated these into

href="http://www.i-feel-a-bit-creutzfeldt-jacob-ish.com/./i_am_going_to_mess_with_your_spider.htm"

So I need to remove substrings like ./ and ../, probably also //.

The problem is I can't. I've tried using string.replaceAll("./", ""),
but that removes other things too as the . is treated as meaning "one char of any kind".

so the previous URL translated would become:

http://www.i-feel-a-bit-creutzfeldt-jacob-ish.coi_am_going_to_mess_with_your_spider.htm"

See my problem?


Any help appreciated.
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
Have you tried delimiting the "." using "\\."
so

becomes

I haven't tried it here myself but it should work!
Mahoney Futhark
Greenhorn

Joined: Nov 15, 2004
Posts: 5
Thanks, worked just fine
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Moving to Java in General(intermediate)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Replacing substrings like ./ and ../
 
Similar Threads
Useful jobsite
a nice, simple game - red dots
Java and Windows COM
Need some help
Suggest the name!!