縦の数字をカンマで区切った形に変換し、重複しない形だけをフィルタする必要があります.

7131 ワード

class Program

    {

        static void Main(string[] args)

        {

            string rpath;     // 

            string wpath;     // 

            string readstring;  // 

            string[] stringarray ;  // 

            string laststring;     // 

            

            rpath = "D:\\a.txt";

            wpath = "d:\\b.txt";

            readstring = ReaderText(rpath);

            stringarray = readstring.Split(',');

            laststring = DeleteSame(stringarray);

            WriteText(wpath,laststring);

            Console.WriteLine("Translate Successfully");

            Console.ReadKey();

        }

        // 

        public static string ReaderText(string path)

        {

            string s = "";

            try

            {

                using (StreamReader sr = new StreamReader(path))

                {

                    string line;

                    while ((line = sr.ReadLine()) != null)

                    {

                        //Console.WriteLine(line);

                        s = s + line + ','; ;



                    }

                    s = s.Remove(s.Length - 1);// 

                }

            }

            catch (Exception e)

            {

                Console.WriteLine("The file could not be read");

                Console.WriteLine(e.Message);

            }

            return s;

        }



        // 

        public static string DeleteSame(string[] stringarry)

        {

            List<string> liststring = new List<string>();

            foreach (string eachstring in stringarry)

            {

                if (!liststring.Contains(eachstring))

                {

                    liststring.Add(eachstring);

                }

            }

            string laststring = "";

            foreach (string eachstring in liststring)

            {

                laststring = laststring + eachstring + ',';

            }

            return laststring.Remove(laststring.Length - 1);

        }



        // 

        public static void WriteText(string wpath,string data)

        {

            try

            {

                using (StreamWriter sw = new StreamWriter(wpath))

                {

                    sw.Write(data);

                }

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

    }