This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Update file name  RSS feed

 
Ranch Hand
Posts: 176
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way in which a text can be entered in the middle of current text from a certain character?

i.e. I pick a file "test.docx" and want to rename it "test_updated.docx"

I know I can remove the last 5 characters and then add in "_updated.docx" but if I choose a file with a ".doc" or ".1" extension then I need to search based on the period not the length of the string.

Basically I want to append "_updated" to the file name but then still keep the same extension in place. but I also do not know what the file name will be until it is chosen.

Any advice?
 
Bartender
Posts: 5854
57
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use String#lastIndexOf('.') to find the last period. Then from that position append together substring(0,index) + "_updated" + substring(index).
 
Marshal
Posts: 64496
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can insert something into the middle of a text file; do you mean to alter the file's name? Go through this Java™ Tutorials section; look at Copying Paths, etc.
 
Marshal
Posts: 24506
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I don't think you can insert something into the middle of a text file; do you mean to alter the file's name? Go through this Java™ Tutorials section; look at Copying Paths, etc.



The question isn't about inserting into the middle of a file, regardless of the reference to "current text". And it isn't even about changing the name of the file, regardless of the title of the post. It's more basic than that, the OP just needs to generate the String which is going to be the new name of the file.
 
John Morgan
Ranch Hand
Posts: 176
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul you are correct... it was as simple as just converting the string, parsing it, adding the text I needed and then reformatting to complete the name.

Thank you all for your answers here.... now on to my next step.
 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!