本文介绍了如何将字符串转换成点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的格式的x,y的字符串列表。我想使它们都转化成得分。最佳点构造可以找我有两个整数。什么是C#把最好的办法14,42
到新点(14,42);
?
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);
?
我知道正则表达式做是 /(\d +),(\d +)/
, 。但我有一个很难转向这两个比赛组到整数在C#
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#.
推荐答案
这样的:
string[] coords = str.Split(',');
Point point = new Point(int.Parse(coords[0]), int.Parse(coords[1]));
这篇关于如何将字符串转换成点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!