Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,
i have one string like string path="C:\\Users\\Dattatray\\Desktop\\Rajendra 12-mar\\BookMyShow\\BookMyShow\\Images\\gabbar-2014.jpg";

i want to do to take only gabbar-2014.jpg in another string like string imgpath="gabbar-2014.jpg";


plz help....
Posted

Try:
C#
string path="C:\\Users\\Dattatray\\Desktop\\Rajendra 12-mar\\BookMyShow\\BookMyShow\\Images\\gabbar-2014.jpg";
string filename = Path.GetFileName(path);
 
Share this answer
 
Comments
Ajith K Gatty 3-Apr-14 6:05am    
Excellent solution OriginalGriff :)
can you try yourself:
substring method in C#
 
Share this answer
 
C#
string[] stp = path.split("//");
string res = stp[stp.length - 1];
 
Share this answer
 
v2
Use string.split and splot on the \ symbol. Then access the last element of the array.
 
Share this answer
 

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