`
caihorse
  • 浏览: 141108 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

去除数组中的重复数据

    博客分类:
  • java
J# 
阅读更多
去除数组中的重复数据(一个或多个数组)
  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;
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics