comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <eachus@mitre.org>
Subject: Re: [newbie] Need som feedback on code snip
Date: 1999/10/22
Date: 1999-10-22T19:10:54+00:00	[thread overview]
Message-ID: <3810B7FE.7C721399@mitre.org> (raw)
In-Reply-To: m31zan4l1n.fsf@kiuk0156.chembio.ntnu.no

  Can I take this one?  Can I?  Can I please... ;-)

Preben Randhol wrote:
  
> I wondered if somebody could take a peep at the code snip below and
> comment on it.

  It works way too hard to do something which is very simple...

> It works, but is is the Right Way to do it or is there
> a smarter way.

-- 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 My_Test 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 My_Test;

   Unbounded strings do for you all that ugly pointer and memory
allocation and reclamation stuff that you have to worry about in C. 
And,
if you are using GNAT, there is a package Ada.Strings.Unbounded.Text_IO,
that makes it still easier:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
procedure Test2 is
   Text: Unbounded_String := To_Unbounded_String("Hello world!");
begin
   Put_Line(Text);
   Text := To_Unbounded_String("Hello yourself!");
   Put_Line(Text);
end Test2;
 
-- 

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  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 ` [newbie] Need some " Matthew Heaney
1999-10-22  0:00 ` [newbie] Need som " Ted Dennison
1999-10-22  0:00   ` Ted Dennison
1999-10-22  0:00 ` Robert I. Eachus [this message]
1999-10-24  0:00   ` Preben Randhol
replies disabled

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