|
发表于 2020-6-8 11:15:01
|
显示全部楼层
protected void Page_Load( object sender, EventArgs e )
{
string a = "aa,bb,cc,dd,aa,bb,cc,dd";
string[] arr = a.Split(',');
string[] b = RemoveDups(arr, true);
for (int i = 0 ; i < b.Length ; i++)
{
Response.Write("<li>" + b[i]);
}
}
public string[] RemoveDups( string[] items, bool sort )
{
ArrayList noDups = new ArrayList();
for (int i = 0 ; i < items.Length ; i++)
{
if (!noDups.Contains(items[i].Trim()))
{
noDups.Add(items[i].Trim());
}
}
if (sort) noDups.Sort();
string[] uniqueItems = new String[noDups.Count];
noDups.CopyTo(uniqueItems);
return uniqueItems;
} |
|