From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e5f1e38db361b33e X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: [newbie] Need some feedback on code snip Date: 1999/10/22 Message-ID: <38109ead_1@news1.prserv.net>#1/1 X-Deja-AN: 539334163 Content-transfer-encoding: 7bit References: Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 22 Oct 1999 17:28:13 GMT, 129.37.62.177 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-10-22T00:00:00+00:00 List-Id: In article , Preben Randhol 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;