How I can modify the code to make work all statements?

前端 未结 2 1205
北海茫月
北海茫月 2021-01-28 17:46

I have the next code :

private void Install_Click(object sender, EventArgs e)
{

    string configfilename = path + \"config.ini\";
    string installerfilename          


        
相关标签:
2条回答
  • 2021-01-28 18:26

    Try this code.

    string configfilename = path + "config.ini";
    string installerfilename = path + "installer.ini";
    
    var link = File.ReadLines(path + "config.ini").ToArray();
    var lin = File.ReadLines(path + "installer.ini").ToArray();
    IEnumerable<string> newInstaller = lin;
    foreach (var txt in link)
     {
    
         if (txt.Contains("PLP="))
         {
            var PLPPath = txt.Split('=')[1];
            newInstaller = newInstaller.Select(line => Regex.Replace(line, @"fileInstallationKey=.*", "fileInstallationKey=" + PLPPath));                   
         }
         if (txt.Contains("Output="))
         {
             var outputPath = txt.Split('=')[1];
             newInstaller = newInstaller.Select(line => Regex.Replace(line, @"outlog=.*", "outlog=" + outputPath));  
         }
     }
    newInstaller = newInstaller.Select(line => Regex.Replace(line, @"license=.*", "license=yes"));
    newInstaller = newInstaller.Select(line => Regex.Replace(line, @"lmgr_files=.*", "lmgr_files=false"));
    newInstaller = newInstaller.Select(line => Regex.Replace(line, @"lmgr_service=.*", "lmgr_service=true"));
    
    string strWrite = string.Join(Environment.NewLine, newInstaller.ToArray());
    
    File.WriteAllText(installerfilename,strWrite);
    
    0 讨论(0)
  • 2021-01-28 18:34

    There is a mechanism to read/write to ini file. There is no need to re-invent the wheel here. Take a look at Reading/writing an INI file

    0 讨论(0)
提交回复
热议问题