.NET 6 Path.GetFileNameWithoutExtension() 方法详解 - 获取文件名不含扩展名
Path.GetFileNameWithoutExtension() \u662f .NET 6 \u4e2d \u7528\u4e8e\u83b7\u5f97\u6587\u4ef6\u8def\u5f84\u4e2d\u6587\u4ef6\u540d\uff08\u4e0d\u542b\u6269\u5c55\u540d\uff09\u7684\u9759\u6001\u65b9\u6cd5\u3002\u672c\u7bc7\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8be5\u65b9\u6cd5\u7684\u8bed\u6cd5\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u548c\u793a\u4f8b\uff0c\u5e2e\u52a9\u4f60\u66f4\u597d\u7684\u7406\u89e3\u548c\u4f7f\u7528\u5b83\u3002\n\n\u8bed\u6cd5\uff1a\ncsharp\npublic static string GetFileNameWithoutExtension(string path);\n\n\n\u53c2\u6570\uff1a\n- path\uff1a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u6587\u4ef6\u8def\u5f84\u3002\n\n\u8fd4\u56de\u503c\uff1a\n- \u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u6587\u4ef6\u540d\u7684\u6587\u4ef6\u540d\u90e8\u5206\uff0c\u4e0d\u542b\u6269\u5c55\u540d\u3002\n\n\u793a\u4f8b\uff1a\ncsharp\nstring filePath = \"C:\\Users\\username\\Documents\\example.txt\";\nstring fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);\nConsole.WriteLine(fileNameWithoutExtension); // \u8f93\u51fa\uff1a\"example\"\n\n\n\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6587\u4ef6\u8def\u5f84\u662fC:\Users\username\Documents\example.txt\uff0c\u4f7f\u7528 Path.GetFileNameWithoutExtension() \u65b9\u6cd5\u83b7\u5f97\u6587\u4ef6\u540d\u7684\u6587\u4ef6\u540d\u90e8\u5206\uff0c\u5c31\u662f"example"\uff0c\u7136\u540e\u5c06\u5b83\u6253\u5370\u8f93\u51fa\u3002
原文地址: https://www.cveoy.top/t/topic/qmvM 著作权归作者所有。请勿转载和采集!