如何在c#中关闭文件路径[关闭]

问题描述 投票:0回答:1
我正在尝试修剪文件路径:E:\ User \ Net framework Automation \ Ecom.Optimus.Automation \ Ecom.Optimus.Automation \ bin \ Debug \ Ecom.cvf.Automation.dll

输出类似E:\ Sudharsan \ Net框架Automation \ Ecom.Optimus.Automation \ Ecom.Optimus.Automation

如何用C#编写

c# file path trim
1个回答
0
投票
这对我来说很好:

using System; public class Program { public static void Main() { String str = @"E:\User\Net fwramework Automation\Ecom.Optimus.Automation\Ecom.Optimus.Automation\bin\Debug\Ecom.cvf.Automation.dll"; Console.WriteLine(str.Substring(0, str.LastIndexOf(@"\bin"))); } }

使用.LastIndexOf获取字符串中的最后一个“ \ bin”,然后使用.Substring将其删除

如果您想删除一些复杂的东西,也可以使用正则表达式。

© www.soinside.com 2019 - 2024. All rights reserved.