日期:2014-05-17 浏览次数:20460 次
string str1="1,2,3,4,5,6,7,1,2,3,4,5";
string str3="1,2.3,4,5,6,7";
string[] stest = new string[] { "aaa", "bbb", "ccc", "aaa", "ccc" }; ArrayList list = new ArrayList(); for (int i = 0; i < stest.Length; i++) { bool IsExist = true; for (int j = 0; j < list.Count; j++) { if (list[j].ToString() == stest[i]) { IsExist = false; break; } } if (IsExist) { list.Add(stest[i]); } }
------解决方案--------------------
string strA="a,b,c,d,e,f"; string strB="a,b,d,f,g,h"; string[] ArrayA=strA.split(','); string[] ArrayB=strB.split(','); string[] ArrayB= ArrayA.Union(ArrayB.Where(str => !ArrayA.Contains(str))).ToArray();
------解决方案--------------------
using System.Linq; string origin = "1,2,3,4,5,6,7,4,5,7"; var array = origin.Split(new string[]{","}, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray(); string des = String.Join(",", array); Console.WriteLine(des);
------解决方案--------------------
string str = "1,2,3,4,5,6,7,1,2,3,4,5";
ArrayList arr = new ArrayList();
arr = CleanRepeat(str);
foreach (object var in arr )
{
Console.WriteLine(var.ToString());
}
Console.ReadLine();
static ArrayList CleanRepeat(string str)
{
string[] temp;
ArrayList arraylist = new ArrayList();
temp = str.Split(',');
arraylist.Add(temp[0]);
for (int i = 0; i < temp.Length; i++)
{
if (arraylist.IndexOf(temp[i]) != -1)
{
continue;
}
else
{
arraylist.Add(temp[i]);
}
}
return arraylist;
}
------解决方案--------------------
string str1 = "1,2,3,4,5,6,7,1,2,3,4,5"; string str3 = null; for (int i = 0; i < str1.Length; ) { string str2 = str1.Substring(i, 1); if (i == 0) str3 += str2; if (i >= 2 && str3.IndexOf(str2) < 0) str3 += "," + str2; i = i + 2; }
------解决方案--------------------
string str1 = "1,2,3,4,5,6,7,1,2,3,4,5";
str1 = string.Join(",", str1.Split(',').Distinct().ToArray());