"LastIndexOf" doubt
-
string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP
-
string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP
Hello, to split a string, you would use the: String.Split[^] method. Dealing with filename and pathes you could use the fancy features of System.IO.Path[^] namespace! In your case, the GetFileName[^] method will do what you need.
string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = System.IO.Path.GetFileName(strPath ); /will return: 'XML Tutorial(Basics).doc'
Hope it helps!All the best, Martin
-
string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP
Hi, Use the following: string filename=System.IO.Path.GetFileName("YourFilePath");
Naresh Patel
-
string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP
you can use System.IO.Path Class to do that like
string path=@"C:\my Pics\test.bmp"; string fileName=System.IO.Path.GetFileName(path);
good luck