我有一个文件位置FileName ="C:\ Data\PronetContent\Content\Versions\14602\Working\1234.htm"
我需要字符串的一部分,除了htm文件名 - 1234.htm
所以我想要的结果是"C:\ Data\PronetContent\Content\Versions\14602\Working"
我实现了这段代码:
string[] fileLocation = FileName.Split('/');
string[] fileLocation1 = fileLocation.Take(fileLocation.Count() - 1).ToArray();
string Floc = string.Join("/", fileLocation1);
Run Code Online (Sandbox Code Playgroud)
但我得到一个空字符串.请帮忙
首先,使用拆分/为基于Windows的机器,不会拆分你的字符串,因为它拆分为\
您可以使用
Path.GetDirectoryName()
Run Code Online (Sandbox Code Playgroud)
所以,
Path.GetDirectoryName(FileName)
Run Code Online (Sandbox Code Playgroud)
将回归你的道路