Bit Byte wrote:
I am passing data as a string arg to a function. I'd like to determine
whether the data is 'text' (i.e. alpha || alphanumeric), ineteger or
double).
enum
{
TEXT,
INTEGER,
DOUBLE
}DataType ;
DataType foo(const string& arg)
{
//determine data type
...
};
Any ideas how to do this ?
First you'd have to come up with a list of criteria that define your 'text',
'integer' and 'double'. It is probably natural thing to do to arrange the
criteria in hierarchical fashion: first test for 'double', then for 'integer'
and the rest is 'text'. But what about the details of each format? Are you
planning to use the C++ language definitions for integer and floating-point
literals? Or maybe formats recognized by string conversion functions (like
'scanf' and 'strtol')? Or you have something else in mind? For example, is '0x1'
an 'integer' or a 'text'? Is '1e+5' an allowed format of your 'double'? What
about ' 5 ' (with these extra spaces)? Is it an 'integer' or a 'text'?
--
Best regards,
Andrey Tarasevich