Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to get last string in example below:
D:/MyData/Account

can i possible to get string Account in C#?i need to help to solve this problem. thankyou.
Posted
Comments
agent_kruger 21-Jun-14 5:29am    
sir, on what base you wait Accounts?

Yes - it's pretty simple:
C#
string path = @"D:/MyData/Account";
string name = Path.GetFileName(path);

Or if it could be an actual file name and you don't want the extension:
C#
string path = @"D:/MyData/Account.xlsx";
string name = Path.GetFileNameWithoutExtension(path);
 
Share this answer
 
Comments
Ade.Ruyani.Z 21-Jun-14 1:50am    
Thank you Griff, your very helpfull
OriginalGriff 21-Jun-14 2:11am    
You're welcome!
Debabrata_Das 21-Jun-14 1:58am    
my 5!
Nirav Prabtani 21-Jun-14 4:57am    
My 5+ to compensate down vote..
Change your code as below:
C#
string path = "D:/MyData/Account";
string myValue = path.Substring(path.LastIndexOf("/") + 1, path.Length - path.LastIndexOf("/") - 1);

Output: Account
 
Share this answer
 
Comments
Raul Iloc 21-Jun-14 10:04am    
This is the best answer. You have my vote 5!
[no name] 21-Jun-14 10:53am    
Thanks Raul. I appreciate your feedback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900