Binaryformatter question

Hey,

I’m using the Binaryformatter to save my game in a dat file, every time i save it overwrites the file.

Id like to save my game’s settings in the same dat file without having to overwrite the whole file, is it possible to only modify some variables in the dat file without overwriting the others, or should i have a separate file for the settings?

Thanks

You can do something like:

using System.Text.RegularExpressions; //Add this using statement.

string _saveData = "Player life = 10, player power = 30"; //Example of save data text file

private float _playerLife = 100;

    void SetLifeValue()
    {
        string life = "";

        {
            //Here is the patter for obtain the player life.
            var regex = new Regex("Player life = (.+?),"); 

            //Here  i am getting the player life.
            life = regex.Match(_saveData).Groups[1].Value; 
        }

      
        var updatedFile = 
        Regex.Replace(_saveData,"Player life = " + life, "Player life = " + _playerLife);

        //Save the file with the updatedFile variable...
    }