比如:
1,2,2,6,78,9,10,6
变为1,2,6,78,9,10这个如何写(c#)

解决方案 »

  1.   


    string source = "1,2,2,6,78,9,10,6";
            string result = "";
            System.Collections.Generic.List<string> stringList = new System.Collections.Generic.List<string>();
            string[] strList = source.Split(',',StringSplitOptions.RemoveEmptyEntries);
            foreach (string str in stringList)
            {
                if (!stringList.Contains(str))
                {
                    stringList.Add(str);
                    result += str + ",";
                }
            }
            //执行循环后result="1,2,6,78,9,10,6,";
            result.Remove(result.Length - 1);//移除最后一个',',result="1,2,6,78,9,10,6";
      

  2.   

     string str = "1,2,2,6,78,9,10,6";
            string newstr="";
            List<string> str1 = new List<string>();        foreach (string s in str.Split(','))
            {
                if (!str1.Contains(s))
                    str1.Add(s);
            }        
            foreach (string s in str1)
            {
                newstr += s+",";
            }
            newstr = newstr.Remove(newstr.Length - 1);
      

  3.   

    http://topic.csdn.net/t/20041210/14/3633655.html
    看这个帖子8楼的答案!