Reputation: 8928
I need to convert a string path to a Geometry and back again.
The first step is to convert my path: "M 100 100 L 300 100 L 200 300 z"
. To do this I use the Geoemtry.Path method, that creates a new Geometry instance from the specified string:
var geometry = Geometry.Parse("M 100 100 L 300 100 L 200 300 z");
Of this geometry I need to store, in my data structure, its path, that I get using the Geometry.ToString
method:
string str = geometry.ToString();
// And this is my str: "M100;100L300;100 200;300z"
Now I want to recreate the same geometry using the stored path, therefore I use again the Grometry.Parse
method:
// Here i get a FormatException
var geometry2 = Geometry.Parse(str);
The problem is I get a FormatException
!
How is it possible? How can I fix it?
Upvotes: 3
Views: 3378
Reputation: 18578
I guess this is the problem with the Culture
of your machine as it is set to some other culture
than en-Us
. Because the path values should be comma/space seperated in order to be parsed while in your case ToString()
is returning the semi colon seperated values. Try using CultureInfo.InvariantCulture
while converting the Geometry
to string
. It will fix the exception
string str = geometry.ToString(CultureInfo.InvariantCulture);
Upvotes: 4