C#文字檔案內容搜尋(C# search content of the text file)

C#文字檔案內容搜尋(C# search content of the text file)

C#文字檔案內容搜尋(C# search content of the text file)


 

資料來源:

http://jashliao.pixnet.net/blog/post/206148181

http://jashliao.pixnet.net/blog/post/206071093

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

namespace CS_Console_File_Search_Content

{

    class Program

    {

        static
void Pause()

        {

            Console.Write(“Press any key to continue . . . “);

            Console.ReadKey(true);

        }

        static
void Main(string[]
args)

        {

            Boolean
blnSearch=false;

            if
(System.IO.File.Exists(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @”\v7_config.csv”))

            {

                //有3

                StreamReader
sr = new StreamReader(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @”\v7_config.csv”);

                while
(!sr.EndOfStream)//
每LC次¡M讀a取Lu一@行a,A直?到Li檔E尾±A

                {

                    string
line = sr.ReadLine();//
讀a取Lu文a字r到Li line 變U數A

                    if(line.Contains(“server_ver”))

                    {

                        Console.WriteLine(line);

                        blnSearch=true;

                        break;

                    }

 

                }

                sr.Close();// 關o閉?串e流y

                if(!blnSearch)

                {

                    Console.WriteLine(“沒LS有3找±a到Li相U關o資Me料A”);

                }

            }

            else

            {

                Console.WriteLine(“沒LS有3檔E案¡Ñ”);

            }

 

            Pause();

        }

    }

}

 

 

 


 


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *