how to do an isnumeric
-
i am trying to do something like this if(abc=numeric) cout << "abc is numeric"; obviyesly this does not work can anyone giv me the code for the is numeric function thx^^
Well are you trying to test if its equal, because if you are then you meant to do if(abc==numeric) cout << "abc is numeric"; edit: sorry i dont think i read that right, maybe you might try googling the "isnum" function.
-
i am trying to do something like this if(abc=numeric) cout << "abc is numeric"; obviyesly this does not work can anyone giv me the code for the is numeric function thx^^
isalphanum && !isalpha. You need to do it char by char, if you have a std:string you can use a function object to do this. Christian Graus - Microsoft MVP - C++
-
i am trying to do something like this if(abc=numeric) cout << "abc is numeric"; obviyesly this does not work can anyone giv me the code for the is numeric function thx^^
I found this in one of my old libraries. Ignore the CHECK, it's an internal macro.
/// Determines if a string is numeric
/// @param lpszText Text to determine numericy of
/// @param bSigned Determines if the function tests against signed or unsigned
/// numbers
/// @param nBase Numeric base to test against
/// @return True if the string is numeric, false if not
BOOL AfxIsNumeric(LPCTSTR lpszText, BOOL bSigned, int nBase)
{
CHECK(lpszText != NULL, FALSE);// Convert the text to a number using the appropriate sign oriented // function LPTSTR lpszEndPtr = NULL; if (bSigned) \_tcstoi64(lpszText, &lpszEndPtr, nBase); else \_tcstoui64(lpszText, &lpszEndPtr, nBase); // If the end pointer points to the null terminator, and it doesn't point to // the start of the text, (which would occur on an empty string) it's a // valid number return ((lpszEndPtr != lpszText) && (\*lpszEndPtr == \_T('\\0')));
}
:suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Painted on the side of a dog trainer's van: SIT HAPPENS -
i am trying to do something like this if(abc=numeric) cout << "abc is numeric"; obviyesly this does not work can anyone giv me the code for the is numeric function thx^^
Try something like this:
#include <ctype.h>
bool IsNumeric(const char* p)
{
int len = strlen(p);
for (int i = 0; i < len; i++)
{
if (!isdigit(p[i]))
return false;
}
return true;
}Note: I didn't compiled it, so it may contain some error :) -- jlr http://jlamas.blogspot.com/[^]
-
isalphanum && !isalpha. You need to do it char by char, if you have a std:string you can use a function object to do this. Christian Graus - Microsoft MVP - C++
-
Yeah, someone else answered that. I'd never seen that - I am self taught, and when I looked for isnumeric, I obviously didn't spot isdigit, and I kept using that method ever since. Live and learn, I guess.... Christian Graus - Microsoft MVP - C++
-
Yeah, someone else answered that. I'd never seen that - I am self taught, and when I looked for isnumeric, I obviously didn't spot isdigit, and I kept using that method ever since. Live and learn, I guess.... Christian Graus - Microsoft MVP - C++
I'm also self taught. I came across that function a few weeks ago when I also needed to chech if a string was numeric or not. It's not the ideal solution since it will return false on hexa decimal numbers, but it's a start.. :) Christian Graus wrote: Live and learn, I guess.... We developers only stop learning when we die.. If you stop learning, you'll soon be obsolete. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]