字串遞迴獲取指定字元位置內容資訊
阿新 • • 發佈:2018-11-29
針對目前字串處理indexof 無法直接獲取指定到的位置字元處理
/// <summary> /// 字串擷取,獲取 /// 原字串:啊啊啊\\不不不\\擦擦擦\\嗯嗯嗯\\打算 /// 次數是1: 啊啊啊\\不不不\\擦擦擦\\ /// 次數是2: 啊啊啊\\不不不 /// </summary> /// <param name="cop">源字串</param> /// <param name="index">擷取次數</param> /// <returns></returns> private string StrSubOpr(string cop,int index) { int lastfirstindex = cop.LastIndexOf('\\');//倒數第一個位置 string firststr = cop.Substring(0, (lastfirstindex)); if (index == 0) return firststr; else return StrSubOpr(firststr, (index - 1)); }