I program in WPF C#. I have e.g. the following Path:
C:\Program Files\hello.txt
and I want to output "hello" from it.
The path is a string extract from database. Currently I'm using the following method (split from path by '\' then split again by a '.'):
string path = "C:\\Program Files\\hello.txt";
string[] pathArr = path.Split('\\');
string[] fileArr = pathArr.Last().Split('.');
string fileName = fileArr.Last().ToString();
It works, but I believe there should be shorter and smarter solution to that. Any idea?
try
demo
https://msdn.microsoft.com/en-gb/library/system.io.path.getfilenamewithoutextension%28v=vs.80%29.aspx
try
http://msdn.microsoft.com/de-de/library/system.io.path.getfilename.aspx
Try this:
This will return "hello" for fileName.