Convert from string to system.drawing.point c#

kartal picture kartal · Apr 28, 2012 · Viewed 9k times · Source

I want to convert from string {X=-24,Y=10} which generated by Point.ToString(); to Point again?

I save the string value in xml file in save mode and I want read it back to point again in read mode.

Answer

Royi Namir picture Royi Namir · Apr 28, 2012
var myStringWhichCantBeChanged="{X=-24,Y=10}";
var g=Regex.Replace(myStringWhichCantBeChanged,@"[\{\}a-zA-Z=]", "").Split(',');

Point pointResult = new Point(
                  int.Parse (g[0]),
                  int.Parse( g[1]));