Divide text into parts

I want to split this text into 2 parts using a C # .Net windows application.

C:\Users\Microsoft\Pictures\2010-04-22\003.jpg

      

First part: C:\Users\Microsoft\Pictures\2010-04-22\

The second part: 003.jpg

Thanks.

+2


a source to share


3 answers


If you are working with files and paths, use FileInfo:

System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\Users\Microsoft\Pictures\2010-04-22\003.jpg
");
string dir = f.DirectoryName;
string file = f.Name;

      



Or, as Marcelo Cantos says, you can use System.IO.Path. Using Reflector, you can see that the filename FileInfo.Directory calls Path.GetDirectoryName (base.FullPath), so it looks a lot like

+7


a source


Use the class System.IO.Path

:



Path.GetDirectoryName(path);
Path.GetFileName(path);

      

+6


a source


var name = new FileInfo(@"C:\Users\Microsoft\Pictures\2010-04-22\003.jpg").Name;

      

+1


a source







All Articles