-1

伙计们,我使用这个简单的代码来读取 mp-config.cfg 文件,但只是读取。我如何检查这一行:

r_full "value"

如果此行的值为“0”,则返回此错误:

"Sorry but have to use full Screen mod."

然后强制将值写入“1”

我的代码:

using System;
using System.IO;

namespace checkFull
{
    class TextFileReader
    {
    static void Main(string[] args)
    {
        Textreader tr = new StreamReader(@"player\mp-config.cfg");

        how do that?

        // close the stream
        tr.Close();
       }
    }
}
4

2 回答 2

0
string[] parts = File.ReadLines(@"player\mp-config.cfg")
                    .Select(line => line.Split())
                    .Where(x => x.Length > 1)
                    .FirstOrDefault(x => x[0] == "r_full");

string result="";
if (parts != null)
{
   result = parts[1];
}
于 2013-05-26T18:41:32.467 回答
-1
    class TextFileReader
    {
        static void Main(string[] args)
        {
            string path = @"player\mp-config.cfg";
            string readText = File.ReadAllText(path);

            string secondWord = readText.Split()[1];
            int value = Int32.Parse(secondWord);

            if (value == 0)
            {
                Console.WriteLine("Sorry but have to use full Screen mod.");
                using (StreamWriter outfile = new StreamWriter(path))
                {
                    outfile.Write("r_val 1");
                }
            }
        }
    }
于 2013-05-26T18:42:37.300 回答