字符串树节点路径转成List-Id|如,0,2,3,5, 转成 2|3|5
2018-01-18 17:37:27 访问(3283) 赞(1) 踩(0)
/// <summary>
/// 字符串树节点路径转成List-Id|如,0,2,3,5, 转成 2|3|5
/// </summary>
/// <param name="strPath"></param>
/// <returns></returns>
public List<string> StrTreePathToList(string strPath)
{
if (strPath == null||strPath.Length == 0)
return null;
strPath = strPath.Trim();
if (strPath.Length == 0)
return null;
if (strPath.StartsWith(","))
strPath = strPath.Substring(1);
if (strPath.EndsWith(","))
strPath = strPath.Substring(0, strPath.Length - 1);
if (strPath.Length == 0)
return null;
string[] sA = strPath.Split(',');
if (sA == null || sA.Length == 0)
return null;
List<string> theResult = new List<string>();
string strTmp = null;
foreach (string s in sA)
{
if (s == null || s.Length == 0)
continue;
strTmp = s.Trim();
if (strTmp.Length == 0 || strTmp == "0")
continue;
theResult.Add(strTmp);
}
return theResult;
}
上一条:
下一条:
相关评论
发表评论