On Apr 6, 6:29 pm, nils.toenis...@[EMAIL PROTECTED]
wrote:
> On 6 Apr., 22:29, "winston19842...@[EMAIL PROTECTED]
"
>
>
>
> <winston19842...@[EMAIL PROTECTED]
> wrote:
> > On Apr 6, 3:58 pm, nils.toenis...@[EMAIL PROTECTED]
wrote:
>
> > > Hello everybody,
>
> > > beeing new to delphi / pascal i am searching a possibility to read
> > > variables from a string just the same way you use readln to read
> > > variables from a textfile - equivalent to the C function sscanf.
>
> > > I want to extract data from a textfile. When a certain word is found
> > > a the beginning of the current line then i want to read the
following
> > > data (three double variables) in the line into variables.
>
> > What is the format of the data?
> > How would you write it in C?
> > There is no built-in equivalent to sscanf in Pascal. Technically, C
> > doesn't have a built-in function either. sscanf is part of a library.
> > Delphi probably has such a function in a library somewhere - I don't
> > know Delphi.
>
> > I'd do a look where I look for the location of the "trigger" word
> > starting at position 1 of the record. Then the reading of the three
> > doubles depends on how they are represented in the record.
>
> Hello,
> the file is just an ASCII file with different data cards. I am
> searching for those lines starting with the word GRID.
> For example
>
> ....
> GRID 23.5 25.3 54.7
> ....
>
> The program looks like this:
>
> ...
> var
> f:Textfile;
> line:string;
> ...
>
> while not Eof(f) do
> begin
> readln (f,line);
> if AnsiStartsText ('Grid',line) then
> begin
> //Here I want to extract the three double values from the string
> line
>
> end;
> end;
> ...
>
> Maybe this is an wrong approach in delphi or pascal?
Not familiar with AnsiStartsText, but it sounds like my Pascal's
Position - anyway...
I wonder if you replaced the "readln" with a "read (f,rectest)" where
rectest is a string, then check if it is 'Grid', then follow that with
a "readln(f,num1,num2,num3)" where num* are doubles...
read should just read the first field into your string variable, and
leave the rest of the record available to following reads (or readlns
which will read the rest of the record and move the file pointer to
the next record).


|