Remove file extension from a file name string

前端 未结 12 1686
一个人的身影
一个人的身影 2020-11-27 14:18

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(

12条回答
  •  抹茶落季
    2020-11-27 15:10

    I used the below, less code

    string fileName = "C:\file.docx";
    MessageBox.Show(Path.Combine(Path.GetDirectoryName(fileName),Path.GetFileNameWithoutExtension(fileName)));
    

    Output will be

    C:\file

提交回复
热议问题