Unity 打包時(shí)批處理修改代碼中參數(shù),指定文件路徑,老的字符,新的字符修改

1.將下邊這段代碼在vs中運(yùn)行,右鍵打開bin路徑,里面有生成.exe的控制臺(tái)程序,然后對(duì)這個(gè).exe配置環(huán)境變量,這樣就可以用批處理修改文本中指定字符啦,如url,channel,channelid,版本號(hào)等,趕快試試吧!

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace replace

{

? ? class Program

? ? {

? ? ? ? static void Main(string[] args)

? ? ? ? {

????????? //args是命令行參數(shù)

? ? ? ? ? ? if (args.Length != 3)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? Console.WriteLine("請(qǐng)輸入文件路徑 替換內(nèi)容 新的內(nèi)容,按照空格隔開");

? ? ? ? ? ? ? ? //Console.WriteLine("請(qǐng)輸入正確的替換要求");

? ? ? ? ? ? ? ? return;

? ? ? ? ? ? }

? ? ? ? ? ? string path = args[0];

? ? ? ? ? ? string oldValue = args[1];

? ? ? ? ? ? string newValue = args[2];

? ? ? ? ? ? try

? ? ? ? ? ? {

? ? ? ? ? ? ? ? FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

? ? ? ? ? ? ? ? StreamReader sr = new StreamReader(fs);

? ? ? ? ? ? ? ? string con = sr.ReadToEnd();

? ? ? ? ? ? ? ? con = con.Replace(oldValue, newValue);

? ? ? ? ? ? ? ? sr.Close();

? ? ? ? ? ? ? ? fs.Close();

? ? ? ? ? ? ? ? FileStream fs2 = new FileStream(path, FileMode.Open, FileAccess.Write);

//清除文本中所有文件,為了防止有多余空格,或者多出多余字符

??????????????? fs2.Seek(0, SeekOrigin.Begin);

? ? ? ? ? ? ? ? fs2.SetLength(0);

? ? ? ? ? ? ? ? StreamWriter sw = new StreamWriter(fs2);

? ? ? ? ? ? ? ? sw.WriteLine(con);

? ? ? ? ? ? ? ? sw.Close();

? ? ? ? ? ? ? ? fs2.Close();

? ? ? ? ? ? }

? ? ? ? ? ? catch (Exception)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? Console.WriteLine("請(qǐng)指定正確的路徑");

? ? ? ? ? ? }

? ? ? ? }

? ? }

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容