Remove file extension from a file name string

前端 未结 12 1720
一个人的身影
一个人的身影 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:00

    You can use

    string extension = System.IO.Path.GetExtension(filename);
    

    And then remove the extension manually:

    string result = filename.Substring(0, filename.Length - extension.Length);
    

提交回复
热议问题