Board index » delphi » Procedure like Readln that reads a string?

Procedure like Readln that reads a string?

We can make a call like:
        Readln(f, i, j, k);
to read the next line from a file and parse it into many variables.

I'm looking for a similar function (let's assume it's called "ScanString")
that will parse a string in the same way:
        ScanString(s, i, j, k);
Intuitively I'd expect there to be such a function in Delphi, but for the life
of me I can't find it anywhere in the help system or the source code of the
RTL. Does anyone know whether such a procedure (or similar) exists?

I'm using D4.

Clive Backham

 

Re:Procedure like Readln that reads a string?


Clive Backham schrieb:

Quote

> We can make a call like:
>         Readln(f, i, j, k);
> to read the next line from a file and parse it into many variables.

> I'm looking for a similar function (let's assume it's called "ScanString")
> that will parse a string in the same way:
>         ScanString(s, i, j, k);
> Intuitively I'd expect there to be such a function in Delphi, but for the life
> of me I can't find it anywhere in the help system or the source code of the
> RTL. Does anyone know whether such a procedure (or similar) exists?

1) Create a TStringList.
2) Put the whole text as one string (s) into the Text property.
3) Now, the Strings property contains the single lines, that is
Strings[0] is the first line, Strings[1] the second and so on.
4) Don't forget to free the TStringList

-Michael

Re:Procedure like Readln that reads a string?


There is a Readln function that works with variables of type Textfile.  I've
used it frequently to read a whole line from a textfile to a string
variable.

In the help, it appears that it can handle multiple variables.  But I've
just tried it and had no luck actually populating all the variables (all the
text went into the first one).  But I'd start there.

Hope this helps.

Ed

Quote
Clive Backham <cl...@capita.nildram.co.uk> wrote in message

news:7vbreo$7k9$1@supernews.com...
Quote
> We can make a call like:
>         Readln(f, i, j, k);
> to read the next line from a file and parse it into many variables.

> I'm looking for a similar function (let's assume it's called "ScanString")
> that will parse a string in the same way:
>         ScanString(s, i, j, k);
> Intuitively I'd expect there to be such a function in Delphi, but for the
life
> of me I can't find it anywhere in the help system or the source code of
the
> RTL. Does anyone know whether such a procedure (or similar) exists?

> I'm using D4.

> Clive Backham

Other Threads