Modifying string length?_(re)

Thu, 1 May 1997 10:50:32 +0100 (BST)


On Thu, 1 May 1997 04:12:47 +0200 Frank Heckenbach  
wrote:
>
>The African Chief wrote:
>
>> >> It would not be too difficult to make "MyStr.length" and "MyStr.String" 
>> >> accessible "record fields" of strings.  Would it be desireable?
>> >
>> >Yes! (At least length; the String part is accessible anyway with s[n].)
>> >
>> >>  I am
>> >> not sure how this fits into the standard ...
>> > 
>> >I'm not, either. If it conflicts, it should be disabled with
>> >"--extended-pascal", I suppose.
>> 
>>  It should be disabled, with "-borlland-pascal" as well.
>
>But how would you translate references to s[0] in BP then? I know, there
>shouldn't be any in most programs, but sometimes it can be useful, e.g. for
>efficiency. But it's ok for me if it's only enabled with {$X+}, see below.

"s[0] := ..." is okay. I do that myself sometimes (but only to set the length 
to zero). What I was referring to was something like;

	"length(s) := ...."
or	"s.length := ..."

- which shouldn't compile (if at all), when using "--borland-pascal".

>Does this mean strings will always have an additional trailing #0? Do the
>string routines currently support this (i.e. automatically add a #0 at the
>end; but they should not recognize #0 as a terminator, but only rely on the
>length field)? That would be good, because it simplifies converting a string
>into a CString a lot (just "CString(@s[1])", right?).

Delphi 2 does this with long strings (I think). If we are going to do it,
perhaps it should only be done for long strings as well?

However, what  happens when you want to add a string to
the end of it? Check this example, and look at the ouput
under Borland;

program Fred;
var
s,s1:string[40];
begin
 s  := 'Fred Smith'+#0;
 s1 := s + 'is okay'; 
 writeln ( s1 ); 
{prints "Fred Smith is okay" - where did the space before "okay" 
come from? I didn't want or put it there - viz; problem with trailing "#0"}
end.

Best regards, The Chief 
Dr Abimbola A. Olowofoyeku (The African Chief, and the Great Elephant)
Author of:  Chief's Installer Pro v3.12 for Win16 and Win32.
Homepage:  http://ourworld.compuserve.com/homepages/African_Chief/
E-mail: laa12@cc.keele.ac.uk



The African Chief (laa12@cc.keele.ac.uk)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es