search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C# 替換 文字檔案內容 – jashliao部落格

C# 替換 文字檔案內容

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

namespace CS_Console_replaceTxT
{
    class Program
    {
        static void Pause()
        {
            Console.Write(“Press any key to continue . . . “);
            Console.ReadKey(true);
        }
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(@”C:\123.vbs”);
            StreamWriter sw = new StreamWriter(@”C:\456.vbs”);
            while (!sr.EndOfStream)// 每次讀取一行,直到檔尾
            {
                string line = sr.ReadLine();// 讀取文字到 line 變數
                line = line.Replace(“jashliao”, “jash.liao”);
                sw.WriteLine(line);// 寫入文字
            }
            sw.Close();// 關閉串流
            sr.Close();// 關閉串流
            Pause();
        }
    }
}

 

 



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦