I have program that save doubles it produce to file and read the file for next run. Problem is when it want to read file for first time in different windows, it could not manage decimal symbol in different windows, some windows use symbol like '.' and some of them use '/' as separator. How can i handle this problem?
load section:
private void Load( string file )
{
if ( File.Exists( file ) )
{
StreamReader reader = new StreamReader( file );
string line = reader.ReadLine();
//I think i should use IFormatProvider here.
m_GamesTrained = int.Parse( line );
//Some code here!but irrelevant to topic
reader.Close();
}
}
and save section:
private void Save( string file )
{
StreamWriter writer = new StreamWriter( file, false );
m_LastGamesTrainedSave = m_GamesTrained;
writer.WriteLine( m_GamesTrained.ToString() );
float[] contactWeights = m_ContactNetwork.GetWeights();
for ( int i = 0; i < contactWeights.Length; i++ )
{
//I think i should use IFormatProvider here too
writer.WriteLine( contactWeights[i].ToString() );
}
writer.Close();
}
using System.Globalization;
For saving data:
number.ToString(CultureInfo.InvariantCulture)
Fore reading numbers:
int.Parse(number,CultureInfo.InvariantCulture);
//you can use float instead of int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With