Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Borland > Re: reading var...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 7 Topic 1019 of 1114
Post > Topic >>

Re: reading variables from string similar to C function sscanf

by "winston19842005@[EMAIL PROTECTED] " <winston19842005@[EMAIL PROTECTED] > Apr 6, 2007 at 06:08 PM

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).
 




 7 Posts in Topic:
reading variables from string similar to C function sscanf
nils.toenissen@[EMAIL PRO  2007-04-06 12:58:42 
Re: reading variables from string similar to C function sscanf
"winston19842005@[EM  2007-04-06 13:29:34 
Re: reading variables from string similar to C function sscanf
nils.toenissen@[EMAIL PRO  2007-04-06 15:23:25 
Re: reading variables from string similar to C function sscanf
nils.toenissen@[EMAIL PRO  2007-04-06 15:29:52 
Re: reading variables from string similar to C function sscanf
"Jason Burgon"   2007-04-07 10:51:21 
Re: reading variables from string similar to C function sscanf
"winston19842005@[EM  2007-04-06 18:08:32 
Re: reading variables from string similar to C function sscanf
"Heinrich Wolf"  2007-04-07 07:25:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 3:02:25 CDT 2008.