从文件名字符串中删除文件扩展名 [英] Remove file extension from a file name string

查看:28
本文介绍了从文件名字符串中删除文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个字符串表示 "abc.txt",是否有一种快速的方法可以获取一个只是 "abc" 的子字符串?

If I have a string saying "abc.txt", is there a quick way to get a substring that is just "abc"?

我不能做 fileName.IndexOf('.') 因为文件名可能是 "abc.123.txt" 或其他东西,我显然只是想去掉扩展名(即"abc.123").

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").

推荐答案

Path.GetFileNameWithoutExtension 方法为您提供作为参数传递的文件名,不带扩展名,从名称中可以看出这一点.

The Path.GetFileNameWithoutExtension method gives you the filename you pass as an argument without the extension, as should be obvious from the name.

这篇关于从文件名字符串中删除文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆