如何讀取嵌入式資源文本文件如何使用StreamReader并以字符串的形式返回?當前腳本使用Windows窗體和文本框,允許用戶在未嵌入的文本文件中查找和替換文本。private void button1_Click(object sender, EventArgs e){
StringCollection strValuesToSearch = new StringCollection();
strValuesToSearch.Add("Apple");
string stringToReplace;
stringToReplace = textBox1.Text;
StreamReader FileReader = new StreamReader(@"C:\MyFile.txt");
string FileContents;
FileContents = FileReader.ReadToEnd();
FileReader.Close();
foreach (string s in strValuesToSearch)
{
if (FileContents.Contains(s))
FileContents = FileContents.Replace(s, stringToReplace);
}
StreamWriter FileWriter = new StreamWriter(@"MyFile.txt");
FileWriter.Write(FileContents);
FileWriter.Close();}
3 回答

滄海一幻覺
TA貢獻1824條經(jīng)驗 獲得超5個贊
byte[] clistAsByteArray = Properties.Resources.CLIST01;
- 3 回答
- 0 關(guān)注
- 762 瀏覽
添加回答
舉報
0/150
提交
取消