C# 调用readline方法逐行替换内容
来源:互联网 发布:sql server安全策略 编辑:程序博客网 时间:2024/05/01 09:44
通过以下方法可以逐行查找并替换内容。
private void UpdateContentInFile(string file, string o_str, string n_str)
{StringBuilder strB = new StringBuilder();
using(FileStream fin = new FileStream(file, FileMode.Open, FileAccess.Read))
using(StreamReader sr = new StreamReader(fin))
try
{
string line = sr.ReadLine();
if (line.Contains(o_str))
{
line = n_str;
}
while (line != null)
{
if (line.Contains(o_str))
{
line = n_str;
}
strB.Append(line + "\r\n");
line = sr.ReadLine();
}
sr.Close();
fin.Close();
}
catch (Exception ex)
{
//show error message
}
using(FileStream fout = new FileStream(file, FileMode.Open, FileAccess.Write))
using(StreamWriter sw = new StreamWriter(fout))
try
{
sw.Write(strB.ToString());
sw.Close();
fout.Close();
}
catch (Exception ex)
{
// show error message
}
}
0 0
- C# 调用readline方法逐行替换内容
- 【Node.js】'readline' 逐行读取、写入文件内容
- C#逐行读取excel所有内容
- 逐行读取readline 和 逐行写入
- python逐行读取文件内容的三种方法
- python逐行读取文件内容的三种方法
- python逐行读取文件内容的三种方法
- python逐行读取文件内容的三种方法
- python逐行读取文件内容的三种方法
- python逐行读取文件内容的三种方法
- 逐行读取文件内容的三种方法
- Python四种逐行读取文件内容的方法
- readLine()方法
- BufferedReader 中的readLine方法读不到内容的原因
- asp调用内容替换html标签
- C# 逐行驱动打印
- C# 逐行驱动打印
- C#正则表达式替换文件内容
- 一些常用正则表达式
- 再理解HDFS的存储机制
- 关于AngularJS
- 认真记录总结工作中的问题
- SQL语句中的USE
- C# 调用readline方法逐行替换内容
- Ios 面试题
- hibernate select 查询方式总结
- UVa 699 - The Falling Leaves
- MAVEN安装教程
- UIActionSheetDelegate协议中定义的监视方法
- jquery选择全选择等
- OpenGL:纹理基础总结
- MongoDB在mongo控制台下的基本使用命令