去除数组中的重复数据(一个或多个数组)

    protected string[] removeDuplicate(string[] ArrInput)
    {
        ArrayList nStr = new ArrayList();
        for (int i = 0; i < ArrInput.Length; i++)
        {
            if (!nStr.Contains(ArrInput[i]))
            {
                nStr.Add(ArrInput[i]);
            }
        }
        return (string[])nStr.ToArray(typeof(string));
    } 


//去除数组中的重复项

 


================== 发送信息,添加手机重复问题(添加的号码内部重复、添加的号码和原来的号码重复)=======================


        /// <summary>
        /// 得到收费用户的信息(去空格)
        /// </summary>
        /// <returns></returns>
        public string[] getChargePhone()
        { 
           string fee=  this.txtMen.Text.Trim();//原来查询的套餐收费用户
           if (!fee.Equals(""))
           {
               string[] fe = fee.Split(';');
               return this.removeDuplicate(fe);
           }
           return null;
        }

        /// <summary>
        /// 得到免费用户的信息(可能有重复)
        /// </summary>
        /// <returns></returns>
        public string[] getFreePhone()
        {
           string free= this.txtAddNum.Text.Trim();//得到添加的免费用户
            if(!free.Equals(""))
            {
                string[] fre = free.Split(';');
                return this.removeDuplicate(fre);
            }
            return null;
        }

        /// <summary>
        /// 去除本数组中的重复和" "
        /// </summary>
        /// <param name="ArrInput"></param>
        /// <returns></returns>
        protected string[] removeDuplicate(string[] ArrInput)
        {
            ArrayList nStr = new ArrayList();
            for (int i = 0; i < ArrInput.Length; i++)
            {
                if (!nStr.Contains(ArrInput[i])&&!ArrInput[i].Equals(""))
                {
                    nStr.Add(ArrInput[i]);
                }
            }
            return (string[])nStr.ToArray(typeof(string));
        } 

 

        /// <summary>
        /// 得到去除重复的号码的免费号码
        /// </summary>
        /// <returns></returns>
        public string[] getEcho()
        {
            if (this.getFreePhone() != null)//后来添加的
            {
                if (this.getChargePhone() != null)//原来查询的
                {
                    string[] add = this.getFreePhone();
                    string[] old = this.getChargePhone();

                    ArrayList nStr = new ArrayList();
                    //先把免费的数据 添加到集合中
                    for (int i = 0; i < add.Length; i++)
                    {
                            nStr.Add(add[i]);
                    }


                    //和老数据比较,有重复的,删除
                    for (int j = 0; j < old.Length; j++)
                    {
                        if (nStr.Contains(old[j]))
                        {
                            nStr.Remove(old[j]);
                        }
                    }

                     return (string[])nStr.ToArray(typeof(string));
                }
                else//原来的为空,则添加后来增加的号码
                {
                    return this.getFreePhone();
                }
            }
            else
            {
                return null;
            }
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值