This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i replace a whole string

 
Germio Rambharos
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic