If I have a string saying "abc.txt"
, is there a quick way to get a substring that is just "abc"
?
I can't do an fileName.IndexOf('.')
because the file name could be "abc.123.txt"
or something and I obviously just want to get rid of the extension (i.e. "abc.123"
).
I used the below, less code
string fileName = "C:\file.docx";
Path.Combine(Path.GetDirectoryName(fileName),
Path.GetFileNameWithoutExtension(fileName));
Output will be
C:\file