wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How can i replace a whole string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can i replace a whole string" Watch "How can i replace a whole string" New topic
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: 1035
    
  10

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i replace a whole string
 
Similar Threads
transform and change the words of a file.txt with java
Simple Eclipse Question
SQL Server 2008r2 Connection Failed
Strings
unable to change the cursor to string.