arraylist数组字符串连接问题,求高手!
arraylist类型 arrayLianHao数组中的元素{ "02", "12", "23", "33", "43", "52" },两两连接,并去掉重复的字符,如:元素1和元素2相连,“0212”,删除重复字符后为012;元素1和元素2相连,“0223”,删除重复字符后为023;然后元素1和3,1和4,1和5,1和6,2和3,2和4,2和5,2和6,3和4……。得到的删除重复字符的字符串放在arrayLianHao1中,
问题:
所写程序可连接字符串,但不能删除重复字符
代码如下:
ArrayList arrayLianHao = new ArrayList();
string [] number = { "02", "12", "23", "33", "43", "52" };
arrayLianHao.AddRange(number);
ArrayList arrayLianHao1 = new ArrayList();
int q = 0;
for (int i = 0; i < 5; i++)
{
for (int j = i + 1; (j < 6) && (q < 15); j++, q++)
{
foreach (char c in arrayLianHao[i]) { if ((arrayLianHao[j].ToString()).IndexOf(c) >= 0) { (arrayLianHao[j].ToString()).Replace(c.ToString(),""); } }
string xinzifu = arrayLianHao[i].ToString() + arrayLianHao[j].ToString();
arrayLianHao1.Add(xinzifu);
}
}
恳请高手解决!!!
------解决方案--------------------
C# code
string[] number = { "02", "12", "23", "33", "43", "52" };
ArrayList arrayLianHao = new ArrayList();
var query = from x in number
from y in number
select new string((x + y).Distinct().ToArray());
foreach (string s in query)
{
arrayLianHao.Add(s);
}