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
       Read(F, s);
       Move(s[1], p^, Length(s));

    End;
    Readln(F);                              { clear eol }
    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;

Then simply use   Readln(F, s);

Take a look at the STRINGS Unit and online help for more information on
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
would have to write your own readln command..


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
with Blockread/Blockwrite?


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

BlockRead. If you know the length ahead of time issue a read for the
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
>would have to write your own readln command..

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
AA>with Blockread/Blockwrite?

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

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
>>would have to write your own readln command..

>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
     read(line);
     write(line);
  end;
  readln;
  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
> >would have to write your own readln command..

> 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
BlockRead/Write.


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
>would have to write your own readln command..

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 ....  
   readln(FileVar,S1,S2,S3,...,Sn);

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}
   Readln(FileVar,S);
   {Close FileVar}
end;



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Reading Text longer than 255 bytes

2. 255 byte PDox field limit!!!

3. Oracle strings longer than 255 ??????

4. Problem with trings longer than 255 ??????

5. strings longer then 255 characters

6. strings longer then 255 characters

7. longer than 255 char strings?

8. String constants longer than 255 characters?

9. Processing Text File Records > 255 Characters

10. Help: Memo.text <= 255?

11. Cannot retrieve MS-SQLServer VARCHAR(n>255) or TEXT field in Delphi program

12. Strings longer than 255 bytes and Memo Fields...Help!!!

 

 
Powered by phpBB® Forum Software