Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\attendence.pdf

The above mentioned is a string.i want to take substring from that.

i want to take the substring 'attendence.pdf' only

Similarly

FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\fromtheliveofthearticle.pdf

i want to take the substring 'fromtheliveofthearticle.pdf' only
etc

The need is that every time i get a path like the string above,each time i want only the last name after '\' symbol.

Kindly help to solve this

Kishore
Posted
Updated 16-Dec-10 19:17pm
v3
Comments
Abdul Quader Mamun 16-Dec-10 23:37pm    
Spelling check.

Try myString.SubString(myString.LastIndexOf("\\")).
 
Share this answer
 
Comments
Ankur\m/ 16-Dec-10 23:42pm    
myString.LastIndexOf("\\") + 1
:)
Abhinav S 17-Dec-10 0:26am    
Thanks Ankur - I left that bit for the OP to figure out. :)
Thank you for your question. You can follow the bellow code.

C#
String strOutput = String.Empty;

//attendence.pdf
String strTemp=@"FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\attendence.pdf";
String [] strArray = strTemp.Split(new Char [] {'\\'});
strOutput = strArray[strArray.Length - 1];//attendence.pdf

//fromtheliveofthearticle.pd
strTemp = @"FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\fromtheliveofthearticle.pdf";
strArray = strTemp.Split(new Char[] { '\\' });
strOutput = strArray[strArray.Length - 1]; //fromtheliveofthearticle.pd



Thanks,
Mamun
 
Share this answer
 
v3
Comments
Аslam Iqbal 17-Jan-11 7:47am    
very simple solution. I mean easy to understand. 5
Suppose you have the string stored in a variable called 'path'.
So, this is how you get the file name part.

C#
string path = @"FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\attendence.pdf";
string fileName = path.Substring(path.LastIndexOf("\\") + 1);
 
Share this answer
 
v2

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