你好,我有以下代碼與線C#正則表達式打破
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string searchText = "find this text, and some other text";
string replaceText = "replace with this text";
String query = "%SystemDrive%";
string str = Environment.ExpandEnvironmentVariables(query);
string filePath = (str + "mytestfile.xml");
StreamReader reader = new StreamReader(filePath);
string content = reader.ReadToEnd();
reader.Close();
content = Regex.Replace(content, searchText, replaceText);
StreamWriter writer = new StreamWriter(filePath);
writer.Write(content);
writer.Close();
}
}
}
替換沒有找到搜索文本,因爲它是在不同的行狀
發現這樣的文字,
和一些其他的文字。
我該如何編寫正則表達式epression,以便它能夠找到文本。
我試圖執行這個方式,但我似乎仍不能替換的文本,如果我做了更換爲它工作 – 2009-05-28 16:08:01
您需要在搜索文本添加換行符一行。嘗試逐字輸入搜索文本。我會編輯我的答案來向你展示。 – Stephan 2009-05-28 16:37:01