我从一个文本文件中读取数据,得到一个string ,然后想将某些字符串替换掉,但是不能成功,请指教:
文本文件:
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = iappProjName, iappProjNamePath, iappProjGuid
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{25A0E2BB-2AF8-4057-A875-C588DC1C2729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25A0E2BB-2AF8-4057-A875-C588DC1C2729}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25A0E2BB-2AF8-4057-A875-C588DC1C2729}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25A0E2BB-2AF8-4057-A875-C588DC1C2729}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal读取的程序如下:            string slnMoban = @"..\..\..\ucodeWinForm\slnMoban.txt";
            StreamReader sr = new StreamReader(slnMoban, System.Text.Encoding.UTF8);
            string readSlnFile = sr.ReadToEnd();
            sr.Close();            readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");
            Console.WriteLine(readSlnFile);
           
            Console.ReadLine();最后看输出,iappProjName无法被替换。请达人帮忙。

解决方案 »

  1.   

    readSlnFile = readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");
    Console.WriteLine(readSlnFile);
      

  2.   

    string s=readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");
    返回的对象才是你要的.
    因为STRING是不可变的.
      

  3.   

    readSlnFile = readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");//需重新赋值
      

  4.   

    晕readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");
    //改为
    readSlnFile = readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");
      

  5.   

    设断点跟踪readSlnFile看,是否把文本读进来了
      

  6.   

    所有的字符串处理都是要取返回新的string.
    内部有string常量池来维护的.不建义大量处理string.
      

  7.   

                string slnMoban = @"..\..\..\ucodeWinForm\slnMoban.txt";
                StreamReader sr = new StreamReader(slnMoban, System.Text.Encoding.UTF8);
                string readSlnFile = sr.ReadToEnd().Replace("iappProjName", "rrrrrrrrrrr");
                sr.Close();            Console.WriteLine(readSlnFile);
               
                Console.ReadLine();
      

  8.   


    readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");
    //改为
    readSlnFile = readSlnFile.Replace("iappProjName", "rrrrrrrrrrr");