关于字符串去重问题的解决


#region 字符串去重
/// <summary>
/// 字符串去重
/// </summary>
/// <param name="strList"></param>
/// <returns></returns>
private string StringUnique(string strList)
{
//1.把字符串转换成数组
string result = string.Empty;
string[] str_num = strList.Split(',');

//2.定义ArrayList,判断数组中重复字段不添加到 ArrayList对象中
ArrayList al = new ArrayList();
for (int i = 0; i < str_num.Length; i++)
{
//判断是否已经存在
if (al.Contains(str_num[i]) == false)
{
al.Add(str_num[i]);
}

}

//3.将arrayList转换成数组
str_num = new String[al.Count];
str_num = (string[])al.ToArray(typeof(string));

//3.数组转字符串,并以逗号间隔
result = string.Join(",", str_num);

return result; ;
}
#endregion

posted @ 2022-02-09 15:37  LowKeyC  阅读(57)  评论(0编辑  收藏  举报
有志者事竟成破釜沉舟百二秦关终属楚苦心人,天不负,卧薪尝胆,三千越甲可吞吴