| Author |
How can i replace a whole string
|
Germio Rambharos
Greenhorn
Joined: May 23, 2012
Posts: 1
|
|
Hey guys i was trying to save a image into a database
I wanted to change the image name
I want to hold the extention though
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 361
|
|
Assuming that you mean you want to replace everything in front of the last full stop then two of the very many approaches are :-
1) Find the index of the last full stop and use substring() to extract the extension. Easy enough to then just create the new file name. (3 lines of code)
2) Use String.replaceFirst() with a regex that select everything up to the last full stop and replace it with your new file name. (1 line of code)
|
 |
 |
|
|
subject: How can i replace a whole string
|
|
|