[英]Get Both the file name and file type as seperate strings in C#
我有下面显示的代码片段
string iName = opFile.SafeFileName;
// here iName = Image1.jpg
现在,我希望文件名和文件类型作为单独的字符串
string a ="Image1";
string b ="jpg";
如何做到这一点,任何帮助表示赞赏。
请查看此 Microsoft 文档以了解System.IO.Path
类。
Path.GetFileNameWithoutExtension(iName);
- 将返回文件名。Path.GetExtension(iName);
- 将返回文件的扩展名。仅供参考 - 如果您不想要“。” 在文件扩展名中,您需要将其删除,因为 Path.GetExtension 函数将其作为字符串中的第一个字符返回,我记得。 (例如 - Path.GetExtension("SomeFile.jpg") 返回 ".jpg")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.