Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return the last string value 1

Status
Not open for further replies.

Ngai88

Programmer
Joined
Sep 8, 2004
Messages
56
Location
US
Hello,

C:\Documents and Settings\Administrator\Expresso\Developer\ DvplrInWordDoc.doc

In order to extract 'Expresso DvplrInWordDoc.doc', I believe I need to parse a string value and return a substring.

What do you do when it is a case that disregard of how the string is being output, I want to grab the filename that is always behind the last '\' of the string. I would like to make it a method and call it.

Any help will be appreciated.

Ngai
 
If this is a file path, then you can ues File object to obtain the filename:

Code:
String path = "C:\\Documents and Settings\\Administrator\\Expresso\\Developer\\DvplrInWordDoc.doc";
File file = new File(path);
System.out.println(file.getName());

using String method you can do:

Code:
String path = "C:\\Documents and Settings\\Administrator\\Expresso\\Developer\\DvplrInWordDoc.doc";
System.out.println(path.substring(path.lastIndexOf("\\")+1));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top