【发布时间】:2013-12-31 20:41:39
【问题描述】:
我目前有一个大文本文件,我正在尝试用 # 替换 "" 内任何内容之间的未知文本。我试过用:
string text = File.ReadAllText(@"c:\Users\Zero\Documents\test.txt");
string replacement = "#";
int start = text.IndexOf('"') + 1;
text = text.Replace(text.Substring(start, text.LastIndexOf('"') - start), replacement);
File.WriteAllText(@"c:\Users\Zero\Documents\test.txt", text);
目前它正在用一行替换文件中的所有文本。换句话说,它正在转向:
你好,“测试”怎么样
这是一个测试“123”测试
“测试”“测试”
进入
“#”
我需要它来做这个
你好吗“#”
这是一个测试“#”测试
“#”“#”
【问题讨论】: