[fpc-devel] Re: fpc-devel Digest, Vol 40, Issue 16

Florian Klaempfl florian at freepascal.org
Fri Oct 19 11:46:38 CEST 2007


L schrieb:
> I wrote:
>> In KOL, Kladov also returns a zero with his Str2Int function if string is bad.
>> You may be thinking.. but what if the string really is a zero and we want to
>> know that it is?
>> Well then we can do this:
>> if (s = '0') or (StrToInt(s) <> 0) then  writeln('S is an integer');
>> if StrToInt('SomeString') = 0 then  writeln('s is not an integer');
>>
> 
> Rather..
> 
> var
>   i: integer;
> begin
>   i:= StrToInt(s);
>   if (s = '0') or (i <> 0) then
>     writeln('S is an integer, and i is now: ', i)
>   else
>     writeln('S is not an integer: ', s);
> end;
> 
> Alternatively:
> 
> function IsInteger(s: string; i: integer);
> begin
>   result:= false;
>   if (s = '0') or (i <> 0) then result:= true;

s can be 00 000 0000 etc. as well as +0 +00 etc.



More information about the fpc-devel mailing list