ASP.NET 字符串去重

string strPlanReceiver = string.Empty;
            string strPlanReceiveRole = string.Empty;
            TaskModel model = new TaskModel();
            SystemManager syMan = new SystemManager();
            model = syMan.GetTaskReceiverInfoByID(TaskID);  //根据TaskID获取任务接收人配置信息

            if (model != null)
            {
                #region 构造接收人、接收人角色字符串,并去重
                //构造接收人、接收人角色字符串,用于发送消息
                strPlanReceiver += model.PlanReceiver + ",";
                strPlanReceiver += model.PlanReceiver0 + ",";
                strPlanReceiver += model.PlanReceiver1 + ",";
                strPlanReceiver += model.PlanReceiver2 + ",";
                strPlanReceiver += model.PlanReceiver3 + ",";
                strPlanReceiver = strPlanReceiver.Trim(',');

                strPlanReceiveRole += model.PlanReceiveRole + ",";
                strPlanReceiveRole += model.PlanReceiveRole0 + ",";
                strPlanReceiveRole += model.PlanReceiveRole1 + ",";
                strPlanReceiveRole += model.PlanReceiveRole2 + ",";
                strPlanReceiveRole += model.PlanReceiveRole3 + ",";
                strPlanReceiveRole = strPlanReceiveRole.Trim(',');

                //字符串去重
                strPlanReceiver = StringUnique(strPlanReceiver);    //接收人字符串去重
                strPlanReceiveRole = StringUnique(strPlanReceiveRole);    //接收角色字符串去重
                #endregion
            }


#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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值