1.自己实现的找到指定路径,感觉方法不太好,有其他方法的记得交流下,让我学习下哈
class StringHelpUnity { /// <summary> /// 返回指定索引目录路径,(原目录索引为0)获取上一级目录则将index=-1, /// 上上一级目录index=-2,依次论推... /// </summary> /// <param name="old_Catalog">原目录路径</param> /// <param name="index">相对于旧目录(索引定义为0)的索引 /// ,例如:获取上一级目录则将index=-1,上上一级目录index=-2,依次论推... /// </param> /// <returns></returns> public static string Catalog(string old_Catalog,int index) { string new_String = ""; switch (index) { case -1: new_String = old_Catalog.Substring(0, old_Catalog.LastIndexOf('\')); break; case -2: new_String= old_Catalog.Substring(0, old_Catalog.LastIndexOf('\')); new_String = new_String.Substring(0, new_String.LastIndexOf('\')); break; case -3: new_String = old_Catalog.Substring(0, old_Catalog.LastIndexOf('\')); new_String = new_String.Substring(0, new_String.LastIndexOf('\')); new_String = new_String.Substring(0, new_String.LastIndexOf('\')); break; default: new_String = old_Catalog; break; } return new_String; }
}