如何读取嵌入式资源文本文件 - How to read embedded resource text file
2020-07-14 06:42
337 查看
问题:
How do I read an embedded resource (text file) using StreamReader
and return it as a string? 如何使用StreamReader
读取嵌入式资源(文本文件)并将其作为字符串返回? My current script uses a Windows form and textbox that allows the user to find and replace text in a text file that is not embedded. 我当前的脚本使用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(); }
解决方案:
参考一: https://stackoom.com/question/Du9s/如何读取嵌入式资源文本文件参考二: https://oldbug.net/q/Du9s/How-to-read-embedded-resource-text-file
相关文章推荐
- How to read Json file or text file in Spark
- Java读取一个文本文件拼接成一个字符串(readFileToString)
- How to write vc resource to a file in vc6.0(在VC6.0中如何把资源文件写成文件)- Software Bind CockHorse Tech(软件绑马技术)- C++ SourceCode
- How to read video frames in hadoop?如何在Hadoop中读取视频帧?
- How to read text file in client side via HTML5
- QT27 how to read text file and display file to a textbrowser or textedit
- How to read a text file attached to a Lotus Notes Document WITHOUT detaching it?
- prjGetWriteINIFile - How to Read-Write INI file using VB & API - 读取/写入INI文件 - VB6 + API - SourceCode - HackerJLY
- How To Embedded StyleSheet File with Custom Control.
- [转]How to Import a Text File into SQL Server 2012
- How to know is the file exist in C++ - 在C++中如何判断文件是否存在
- 如何窥探PDB的秘密?(How to Inspect the Content of a Program Database (PDB) File)
- org.eclipse.core.internal.resources.ResourceException: Could not write to read-only file: '/。。。/bin/
- InternetReadFile如何正确读取二进制文件
- FileReader除了有函数readAsDataURL,另外还有另外两个函数readAsBinaryString 和 readAsText,分别可以将选择的文件读取成二进制和文本格式
- 如何使用OpenCV的处理图像,文字变得锐利和清晰?(How to use OpenCV to process image so that the text become sharp and clea
- HOW TO:程序集内读取内嵌默认资源
- How to insert a resource image, as embedded image in email?
- How to load and execute Thread class when spring configuration loaded (如何在读取spring配置时自启动线程类)
- 【How to read a paper】如何读论文