CString quandry
-
I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)
-
I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)
bool is_chardigit(const CString& str, int index) { // check if CString is long enough first return isdigit(string.GetAt(index)); } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
-
bool is_chardigit(const CString& str, int index) { // check if CString is long enough first return isdigit(string.GetAt(index)); } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
-
I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)
One more thing. I did not read your question completely. There is a better solution. You can do this
bool check_if_dotted_ip(const char* str)
{
return (inet_addr(str) != INADDR_NONE);
}My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
-
I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)