Remove file extension from a file name string

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

    There's a method in the framework for this purpose, which will keep the full path except for the extension.

    System.IO.Path.ChangeExtension(path, null);
    

    If only file name is needed, use

    System.IO.Path.GetFileNameWithoutExtension(path);
    

提交回复
热议问题