04-19 05:22
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[C/C++] MFC / CString의 한글/영문/숫자 구별하기 본문

Programming/C&C++

[C/C++] MFC / CString의 한글/영문/숫자 구별하기

cinema4dr12 2014. 7. 25. 11:28

이번 글에서는 MFC에서 CString으로 입력 받은 문자열의 첫번째 문자가 한글인지 영문인지 숫자인지 알아내는 코드를 소개하고자 한다.


[한글 알아내기]

CString str = _T("ㄱ");
if(0 >= str.GetAt(0) || 127 < str.GetAt(0)) AfxMessageBox(_T("This is Hangeul"));




[영문 알아내기]

CString str = _T("a");
if(isalpha(str.GetAt(0))) AfxMessageBox(_T("This is an Alphabet"));


또는


CString str = _T("a");
if((65 <= str.GetAt(0) && str.GetAt(0) <= 90) || (97 <= str.GetAt(0) && str.GetAt(0) <= 122)) AfxMessageBox(_T("This is an Alphabet"));




[숫자 알아내기]

CString str = _T("3");
if(isdigit(str.GetAt(0))) AfxMessageBox(_T("This is a Numeric"));


또는


CString str = _T("3");
if(48 <= str.GetAt(0) && str.GetAt(0) <= 57) AfxMessageBox(_T("This is a Numeric"));



Comments