C# 문자열을 좌표로 변환하는 방법. (How to convert a String to Point.)
페이지 정보
본문
"100, 50" 또는 "{100, 50}"과 같은 문자열을 C#의 "System.Drawing.Point" 형식으로 변환하는 메소드입니다.
public static Point ConvertPoint(string point)
{
if (string.IsNullOrEmpty(point))
return new Point();
try
{
string[] coords = point.Split(',');
int x = int.Parse(Regex.Replace(coords[0], @"\D", string.Empty));
int y = int.Parse(Regex.Replace(coords[1], @"\D", string.Empty));
return new Point(coords[0].Contains("-") ? x * -1 : x, coords[1].Contains("-") ? y * -1 : y);
}
catch
{
return new Point();
}
}
개발자에게 후원하기
추천, 구독, 홍보 꼭~ 부탁드립니다.
여러분의 후원이 빠른 귀농을 가능하게 해줍니다~ 답답한 도시를 벗어나 귀농하고 싶은 개발자~
감사합니다~
추천0 비추천0
- 이전글문자열을 사이즈로 변환하는 방법. (How to convert a String to Size.) 21.05.08
- 다음글애플TV 2세대에서 넷플릭스 동영상이 재생되지 않는 문제 해결. (Fixed an issue where Netflix videos were not playing on the 2nd generation of AppleTV.) 21.05.08
댓글목록
등록된 댓글이 없습니다.