输入的数组格式:
strinput=”001,002,003,001,001,003,005”;
要求输出的格式:
stroutput=”001,002,003,005”;
具体的程序如下: 程序后台进行处理,因用到list ,需添加引用以下命名空间
using System.Collections.Generic;
程序正式代码:
string strinput="001,002,003,001,001,003,005";
string strouput="";
Array stringArray = strinput.Split(‘,’);
List<string> listString = new List<string>();
//遍历删除重复项
foreach (string eachString in stringArray)
{
if (!listString.Contains(eachString))
listString.Add(eachString);
}//遍历输出
foreach (string string1 in listString) //测试值
{
strouput=strouput+string1+’,';
}
strouput=strouput.Substring(0,strouput.Length-1);//strouput为所输出的字符串