Remove file extension from a file name string

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

    String.LastIndexOf would work.

    string fileName= "abc.123.txt";
    int fileExtPos = fileName.LastIndexOf(".");
    if (fileExtPos >= 0 )
     fileName= fileName.Substring(0, fileExtPos);
    

提交回复
热议问题