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 function replace substring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "function replace substring" Watch "function replace substring" New topic
Author

function replace substring

asmara kb
Greenhorn

Joined: Jul 16, 2004
Posts: 5
Hi,
is there any java function which can replace substring "test.jpg" in a string with substring "test" (delete the ".jpg")? if not, is there any easy way to do it?

looks like replace() can only deal with char, not strings. appreciate your help !
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
Use replaceAll() or replaceFirst().
asmara kb
Greenhorn

Joined: Jul 16, 2004
Posts: 5
Hi,
I should of being more clear. How do you delete the .jpg from test.jpg.


Thanks,
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
See my first post... replace ".jpg" with an empty string.
asmara kb
Greenhorn

Joined: Jul 16, 2004
Posts: 5
Could you give me an example how to do that if all possible.

By the way this is my first time using javaRanch.

Thanks
asmara kb
Greenhorn

Joined: Jul 16, 2004
Posts: 5
I'm still using java version jdk131_06. It's built in with weblogic workshop 7.0 sp 2.
for that matter, replaceAll() method does not exist.
Ahmed Basheer
Ranch Hand

Joined: Apr 15, 2004
Posts: 77
Try this, It should work, I am sure that all of this is in JDK version you are working in.

String tmp = "test.jpg";
String result = tmp.substring(0,(tmp.length()-tmp.lastIndexOf(".")));
System.out.println("yours is " + result);

Bashir
asmara kb
Greenhorn

Joined: Jul 16, 2004
Posts: 5
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: function replace substring
 
Similar Threads
Regular Expression in search and in replace functions
string replac
Replacing Strings with characters, any functions in java that can do this job
Replacing strings like %3C with any functions in java
Strings