: : : : : hello.. I have s:string; and I want to know if the first char is number
: : : : : because I want to make a condition.. so I wrote
: : : : :
: : : : : .....................................
: : : : : uses wincrt;
: : : : : var first,s:string;
: : : : : BEGIN
: : : : : write('F(x)= ');
: : : : : readln(s);
: : : : : first:= copy(s,1,1);
: : : : : if not (first in ['1'..'100']) then
: : : : : .................................
: : : : :
: : : : : but an error happend... : (ordinal expresion expected)..
: : : : : what's wrong and how can I know if the first char is a number in another way if there is ......and thanks
: : : : : ALA
: : : : :
: : : :
: : : : Why don't you use this function:
val(first,x,code)
: : : :
: : : : with x is a variable of integer (or real)
: : : : code will be 0 if the first is a number, and 1 if is isn't
: : : :
: : : : That's simple!
: : : :
: : : but what is the use of the variable x?
: : :
: : :
: : That's the converted value. See help files for more info.
: :
:
: No need to care 'bout it, the important thing is that code is the condition to check if first is a number
: And you should take Zibadian's advice,too
:
The in-operator is much faster and takes less memory than the conversion. This might become very important if you need to perform this check very often, or the memory load must be as low as possible.