Re: test if a string is a valid 'number'?



VB is internationalized => soubroutine must take locale into the account.

In the sample that you didn't like there were numerous number formats.

The DLL is 32 bit, and Assembly code is bad? Here's some code for you that
will:

1. Be internationalized.
2. Be supported on many platforms.
3. Won't require any effort on your part except adding CLR support to your
MFC project.

#include <windows.h>

BOOL IsNumeric( TCHAR* strTest )
{
System::String^ strExpression = gcnew System::String( strTest );
System::Double dblResult;

if( System::Double::TryParse( strExpression, dblResult ) )
return TRUE;
return FALSE;
}

void main( void )
{
BOOL bNumeric = IsNumeric( TEXT( "1245789.00" ) );
bNumeric = IsNumeric( TEXT( "sdf1245789.00" ) );
bNumeric = IsNumeric( TEXT( "+234.43E-24" ) );
bNumeric = IsNumeric( TEXT( "12,234,345.00" ) );
}

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:ak9u531j8gh8m7gsaqg26p506jk9bpratu@xxxxxxxxxx
It is true it takes a bit more work to support multiple locales. It
depends on whether or
not you also want to support postfix sign (which is one of the locale
options). Then the
issue is whether or not you want to accept prefix or postfix signs or
both. None of these
are very hard to add; all you need is a spec. Do you know if the VB
subroutine handles
any of these situations beyond the decimal point?

I'm already getting request to convert code to Win64, if for no other
reason that a
compute-bound 64-bit app actually runs in about 75% of the time of a
32-bit app on the
same platorm.
joe



.