| 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!
|
 |
 |
|
|
subject: function replace substring
|
|
|