Reading Text longer than 255 bytes
Author Message
Reading Text longer than 255 bytes

Is there anyway to read text that is up to 511 bytes in length?

--
Jeff Patterson  --  Fredericton Area Network

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

>Is there anyway to read text that is up to 511 bytes in length?

Jeff, I understand that reading long strings is addressed in the various
FAQs and SWAG articles.  You might want to check them out, they may have
more elegant solutions.

If all you want is something quick-and-dirty then read the text line into
multiple strings.  Each string can handle 255 characters, so 511 character
line would require 3 strings.  (Ex. Readln(F, s1, s2, s3); )
You'll have to add the code to manage the string in pieces.

Another method is to define an array of char and fill it with a line from
the text file.  Something similar to the following can be used to fill such
an array.  The routine uses a pointer to a zero based array to facilitate
pointer arithmetic, the actual array does not have to be zero based.

Function NextLine(F: Text; VAR ArrayOfChar): Integer;
{ --------------------------------------------------- }
{ Read a line as a nul terminated string and          }
{ return the number of characters in the line.        }
{ --------------------------------------------------- }
TYPE tSArray = Array[0..256] of Char;
VAR p: ^tSArray
s: String;
Begin

While NOT(EOLN(F)) Do Begin
Move(s[1], p^, Length(s));

End;
p^[0] := #0;                            { Nul terminate string }
NextLine := Ofs(p^) - Ofs(ArrayOfChar); { Return string length }
End;

If you have 7.0, the easiest solution is to enable extended syntax and
use the STRINGS Unit.

{\$X+}                           { enable extended syntax }
VAR s: Array[0..512] of Char;   { define a string buffer }
f: Text;

handling nul terminated strings.

...red

Knowledge is one of the few things that you
can give away and still keep for yourself.

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

> Is there anyway to read text that is up to 511 bytes in length?

> --
> Jeff Patterson  --  Fredericton Area Network

I think that the Pascal readln command only goes up to 255 characters, so you

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

> >Is there anyway to read text that is up to 511 bytes in length?

> blockread/blockwrite with variables of the following type:

> type
>   LongString = array [1 .. 511] of char;

I know that will give me a larger string, but how can I read text lines

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

>Is there anyway to read text that is up to 511 bytes in length?

>> Not sure quite what you mean by 'read'. But you can always use

length+1 or issue a read for more than you need and search for the end
of line binary zero. (by the way this assumes you define a holding area
such as:-   buffer: array[0..512] of char;)
Martin
Quote:
>--
>Jeff Patterson  --  Fredericton Area Network

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

>> Is there anyway to read text that is up to 511 bytes in length?

>> --
>> Jeff Patterson  --  Fredericton Area Network

>I think that the pascal readln command only goes up to 255 characters, so you

aint you guys never heard of BlockRead?? just give blockread a 511 bytes buffer (or more)
and parse the buffer into proper CRLF lines.

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

AA>> >
AA>> >Is there anyway to read text that is up to 511 bytes in length?
AA>>
AA>> blockread/blockwrite with variables of the following type:
AA>>
AA>> type
AA>>   LongString = array [1 .. 511] of char;

AA>I know that will give me a larger string, but how can I read text lines

You don't. You need to use a different file type than text for

Kim Forwood

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

> Is there anyway to read text that is up to 511 bytes in length?

Declare a buffer of sufficient size and perform a blockread.
Have a look at the on-line help if you don't know about blockread.

Klaus

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

>>I think that the pascal readln command only goes up to 255 characters, so you

>aint you guys never heard of BlockRead?? just give blockread a 511 bytes buffer (or more)
>and parse the buffer into proper CRLF lines.

There's no need for that.  Readln can read lines of any length.  The
main problem you'll have is that string variables are limited to 255
chars, so you need to be careful to read long lines into multiple
strings.  For example:

var
line : string;
begin
while not eol do
begin
write(line);
end;
writeln;
end;

will copy the first line of a text file no matter how long it is.

Duncan Murdoch

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:

> >> Is there anyway to read text that is up to 511 bytes in length?

> >> --
> >> Jeff Patterson  --  Fredericton Area Network

> >I think that the pascal readln command only goes up to 255 characters, so you

> aint you guys never heard of BlockRead?? just give blockread a 511 bytes buffer (or more)
> and parse the buffer into proper CRLF lines.

Yes, BlockRead is all I ever use.  I'm writing a file-type identifier and
I can not figure out how to read text lines using an untyped file and

Wed, 18 Jun 1902 08:00:00 GMT
Reading Text longer than 255 bytes

Quote:
>I think that the pascal readln command only goes up to 255 characters, so you

Sorry, but the 255 character limitation applies only to the maximum length of
a pascal-type string used by readln.

You can, for example, have a readln() that reads in many 255 char strings at
once ....

You can also use readln to read in a null-terminated string up to 65519 chars
(plus one for the null byte at the end) ..

Uses Strings;
{\$X+}
var S: array[0..65519] of char;
FileVar: Text;
begin
{Open FileVar}