CString to Integer
-
I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?
-
I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?
Anonymous wrote: Or is there anyway to limit user to only type in integers? edit controls have a "number only" property. check for it in the resource editor / property viewre. Image Toolkits | Image Processing | Cleek
-
I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?
One good way to parse your strings is to use
_stscanf
like so:int a;
CString mytext = _T("123Hello");
if(_stscanf(mytext, _T("%d"), &a) != 1)
{
// An error happened
}// a now contains the number if parsed correctly
Joel Holdsworth Wanna give me a job this summer? Check out my online CV and project history[^]
-
I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?