comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: [newbie] Need some feedback on code snip
Date: 1999/10/22
Date: 1999-10-22T00:00:00+00:00	[thread overview]
Message-ID: <38109ead_1@news1.prserv.net> (raw)
In-Reply-To: m31zan4l1n.fsf@kiuk0156.chembio.ntnu.no

In article <m31zan4l1n.fsf@kiuk0156.chembio.ntnu.no> , Preben Randhol 
<randhol@pvv.org>  wrote:

> -- Just a small test to see how I can change the content of a string
> -- variable when I do not know the length of the new or old text.
>
> with Text_IO; use Text_IO;
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
>
> procedure myTest is
>    Orig_Text : aliased Unbounded_String := To_Unbounded_String("Hello
world!");
>    type String_ptr is access all Unbounded_String;
>    Text_pointer : String_ptr;
>
> begin
>    Put_Line(To_String(Orig_Text));
>    Text_Pointer := Orig_Text'Access;
>    Text_Pointer.all := To_Unbounded_String("Hello yourself!");
>    Put_Line(To_String(Orig_Text));
> end myTest;

Don't use heap or pointers.  All of that is hidden behind
Unbounded_String.

  procedure MyTest is
    Text : Unbounded_String := To_Unbounded_String ("hello world");
  begin
    Put_Line (To_String (Text));
    Text := To_Unbounded_String ("Hello yourself");
    Put_Line (To_String (Text));
  end;






      parent reply	other threads:[~1999-10-22  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-22  0:00 [newbie] Need som feedback on code snip Preben Randhol
1999-10-22  0:00 ` Ted Dennison
1999-10-22  0:00   ` Ted Dennison
1999-10-22  0:00 ` Robert I. Eachus
1999-10-24  0:00   ` Preben Randhol
1999-10-22  0:00 ` Matthew Heaney [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox