[fpc-pascal] Read() for multiple variables.

surin_bp at mail.ru surin_bp at mail.ru
Wed Apr 2 10:24:01 CEST 2008


zaher dirkey wrote:
> how to use read() procedure to read multiple variable one of them is 
> string type

To read a string and then number it is possible only if the length of a 
line is precisely known and fixed.
I read out one string, and then I find in it numbers. Here an example 
for a finding of real:
--
procedure FindReal(Source: String; VAR Destign: Real;
                         VAR NBeg, CodeOp: Integer);
      CONST
      BegOfNumb: SET OF CHAR = ['0'..'9'];
      NumbChars: SET OF CHAR = ['0'..'9','E','e','+','-','.'];

      VAR
         Buf_String: String;
         Buf_Real  : Real;
         len           : Integer;
      BEGIN
           	CodeOp:=-30;
              len:=LENGTH(Source);
         	if (NBeg<=0) then EXIT;
         	if NBeg>=len then EXIT;
        Buf_String:='';
        While (NOT (Source[NBeg] in BegOfNumb))
                	AND (NBeg < len) do INC(NBeg);
         if NBeg=len then EXIT;
         if NBeg>1 then
           if (Source[NBeg-1]='+') OR (Source[NBeg-1]='-') then 
DEC(NBeg,1);
         While (Source[NBeg] in NumbChars) AND (NBeg<=len) do
         begin
                 Buf_String:=Buf_String + Source[NBeg]; INC(NBeg)
         end;
         Val(Buf_String, Buf_Real, CodeOp);
         if CodeOp=0 then Destign:=Buf_Real
      END;
---
Boris




More information about the fpc-pascal mailing list