/*** 文件路径分离操作类 Austin Liu 刘恒辉 Project Manager and Software Designer E-Mail: lzhdim@163.com Blog: http://lzhdim.cnblogs.com Date: 2024-01-15 15:18:00 使用方法例子: FileSeparateUtil.GetPath(Application.ExecutablePath()); FileSeparateUtil.GetParams(Application.ExecutablePath() + " /h /run /proxy"); ***/ namespace Lzhdim.LPF.Utility { /// <summary> /// 文件路径分离操作类 /// </summary> public sealed class FileSeparateUtil { /// <summary> /// 获取路径中的所有参数 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>所有参数</returns> public static string GetParams(string filePath) { int index = filePath.IndexOf('/'); if (index > 0) { return filePath.Substring(index, filePath.Length - index).Trim(); } else { index = filePath.IndexOf('-'); if (index > 0) { return filePath.Substring(index, filePath.Length - index).Trim(); } } return ""; } /// <summary> /// 获取文件路径 /// </summary> /// <param name="filePath">文件路径(包括参数)</param> /// <returns>文件路径</returns> public static string GetPath(string filePath) { int index = filePath.IndexOf('/'); if (index > 0) { return filePath.Substring(0, index).Trim(); } else { index = filePath.IndexOf('-'); if (index > 0) { int iExt = filePath.LastIndexOf('.'); if (iExt < index) { //如果扩展名在-参数之前,说明有-参数 return filePath.Substring(0, index).Trim(); } } } return filePath.Trim(); } } }
![]() |
Austin Liu 刘恒辉
Project Manager and Software Designer E-Mail:lzhdim@163.com Blog:https://lzhdim.cnblogs.com 欢迎收藏和转载此博客中的博文,但是请注明出处,给笔者一个与大家交流的空间。谢谢大家。 |




浙公网安备 33010602011771号