Sometimes we may need to extract only digits from a string.
For example,
When we display a phone number we display as 001-00-100-200, some thing like that.
but when we save this number is a database as integer, then we need to remove hyphen and other characters.
In such situation we can use this following function.
For example,
When we display a phone number we display as 001-00-100-200, some thing like that.
but when we save this number is a database as integer, then we need to remove hyphen and other characters.
In such situation we can use this following function.
CString GetAllDigits(LPCSTR lpTxt) { CString csDigits; for(;*lpTxt!='\0'; lpTxt++) { if(*lpTxt>=48 && *lpTxt <58) { csDigits += *lpTxt; } } return csDigits; }
No comments:
Post a Comment