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

    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));
    } 


//去除数组中的重复项

 


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


        ///


        /// 得到收费用户的信息(去空格)
        ///

        ///
        public string[] getChargePhone()
        { 
           string fee=  this.txtMen.Text.Trim();//原来查询的套餐收费用户
           if (!fee.Equals(""))
           {
               string[] fe = fee.Split(';');
               return this.removeDuplicate(fe);
           }
           return null;
        }

        ///


        /// 得到免费用户的信息(可能有重复)
        ///

        ///
        public string[] getFreePhone()
        {
           string free= this.txtAddNum.Text.Trim();//得到添加的免费用户
            if(!free.Equals(""))
            {
                string[] fre = free.Split(';');
                return this.removeDuplicate(fre);
            }
            return null;
        }

        ///


        /// 去除本数组中的重复和" "
        ///

        ///
        ///
        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));
        } 

 

        ///


        /// 得到去除重复的号码的免费号码
        ///

        ///
        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;
            }
        }

你可能感兴趣的:(asp.net资料)