Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a string into a Point?

Tags:

c#

regex

I have a list of strings of the format "x,y". I would like to make them all into Points. The best Point constructor I can find takes two ints. What is the best way in C# to turn "14,42" into new Point(14,42);?

I know the Regex for doing that is /(\d+),(\d+)/, but I'm having a hard time turning those two match groups into ints in C#.

like image 813
NateD Avatar asked Nov 28 '22 15:11

NateD


1 Answers

There is Point.Parse (System.Windows.Point.Parse, WindowsBase.dll) and then you don't need to mess around with regex or string splitting etc.

http://msdn.microsoft.com/en-us/library/system.windows.point.parse.aspx

PK :-)

like image 161
Paul Kohler Avatar answered Dec 05 '22 17:12

Paul Kohler