Search code examples
c#csvstring-formattingrect

Rect.ToString() formats with semicolon ("x;y;w;h")


I wonder if someone can help me.

I have an application that uses a config file to store window locations, when I store the location I get it as a Rect and do a simple ConfigSection.SetValue("Location", value.ToString());

99% of the time this string is written as comma separated values x,y,w,h however recently a user complained that our app was raising an exception when opening

After following it through I found that an invalid format exception was raised when parsing a window location, I looked into the config file the location had been written as x;y;w;h, using semicolon as the separator.

I looked at the regional settings and found List Separator, but when I try changing this to a semicolon (as an attempt to replicate the issue), the rect string is still written as comma separated. This means I am unable to replicate locally and do not really know what has caused the issue.

Any insight as to how the separator may have changed would be much appreciated.

Thanks

Kieran


Solution

  • Use InvariantCulture in:

     ConfigSection.SetValue("Location", value.ToString(CultureInfo.InvariantCulture));
    

    In the namespace System.Globalization.

    Then, the format of the string will use a "generic" culture that is exactly the same on all computers (and does not depend on the settings of the computer).