• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Function  RSS feed

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a requirement like this

String filepath = "P:\\Folder1\\Folder2\\Folder3\\Folder4\\Folder5\\Folder6\\File.txt"

String filebase = "P:/Folder1/Folder2/Folder3/";

I want the result string should be filebase = "P:/Folder1/Folder2/Folder3/Folder4/Folder5/Folder6"

 
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, and your question is?

BTW: there is this part of the API that deals with String... take a look, it may have your answers there... google "Java String API"
hariharan jayaprakash wrote:
I have a requirement like this

String filepath = "P:\\Folder1\\Folder2\\Folder3\\Folder4\\Folder5\\Folder6\\File.txt"

String filebase = "P:/Folder1/Folder2/Folder3/";

I want the result string should be filebase = "P:/Folder1/Folder2/Folder3/Folder4/Folder5/Folder6"

 
Saloon Keeper
Posts: 7994
143
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use String manipulations for this. There's a much safer API: java.nio.file.Path.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!