去除字符串中的重复项

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 倒序
{
    class Program
    {
        public static string Get(string str)
        {   
            String[] s = str.Split(new char[] { ';' });
            List<string> list = new List<string>();
            foreach (string a in s)
            {
                if (!list.Contains(a))
                {
                    list.Add(a);
                }
            }
            return string.Join(";", list.ToArray());
        }

        static void Main(string[] args)
        {
            string str = "abcfdfd,adfd,dfdsf,adfd";
            Console.Write(Get(str));
            Console.ReadLine();
        }
    }
}

posted on 2011-11-14 11:47  zg_heng  阅读(248)  评论(0)    收藏  举报

导航