从一个文件名字符串中删除文件扩展名 [英] Remove file extension from a file name string
问题描述
如果我有一个字符串说的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"
).
推荐答案
的<一个href=\"http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx\"><$c$c>Path.GetFileNameWithoutExtension$c$c>方法为您提供了通过不带扩展参数文件名,如应该是清楚的名称。
The Path.GetFileNameWithoutExtension
method gives you the filename you pass as an argument without the extension, as should be obvious from the name.
这篇关于从一个文件名字符串中删除文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!