C#str.Replace只替换第一个字符

时间:2015-07-15 12:03:22

标签: c# string replace character

这是我的代码,我知道它不是最优的,但它对我有用。

 private void textBox_title1_TextChanged(object sender, EventArgs e)
    {
        string title1 = textBox_title1.Text;
        string currentDirectory = Directory.GetCurrentDirectory();
        DateTime folderDate = DateTime.Today;
        string workingFolder = folderDate.ToString("ddMMMyy");
        string mailingDir = ("mailingdir\\");
        string indexPage = (mailingDir + "\\" + workingFolder + "\\" + "index.html");
        String appdir = Path.GetDirectoryName(Application.ExecutablePath);
        String title1open = Path.Combine(appdir, mailingDir, workingFolder, "index.html");
        string str = File.ReadAllText(title1open, Encoding.UTF8);

        str = str.Replace("[title1]", title1);
        File.WriteAllText(title1open, str);
    }

但是,这只会保存输入textBox_title1

的第一个字符

0 个答案:

没有答案