comp.lang.ada
 help / color / mirror / Atom feed
From: Adrian Knoth <adi@thur.de>
Subject: Re: Input a string (again)
Date: 29 Jan 2005 09:53:04 GMT
Date: 2005-01-29T09:53:04+00:00	[thread overview]
Message-ID: <slrncvmn80.98o.adi@ppc201.mipool.uni-jena.de> (raw)
In-Reply-To: 36119gF4r0h1aU2@individual.net

Stefan Merwitz <thebiggestfan2002@yahoo.de> wrote:

Hi!

>      function InputString return string is
>          sString: String(1..30); -- constrained

Why don't you use an unbounded string?

> All I want is to cancel that loop when nothing is entered, help!

with Ustrings; use Ustrings;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure bla is
   HobbyString : Ustring;
begin
   loop
      Get_Line (HobbyString);
      exit when Empty (HobbyString);
      Put_Line (HobbyString);
   end loop;
end bla;

The ustrings-package was written by David A. Wheeler. You can find it
in the adabill-sourcepackage on my homepage (http://adi.thur.de)      
   
If you don't want to use ustrings you may rewrite your program like this:

  function InputString return String is
     buffer : String (1 .. 30);
     iLength : Positive;
  begin
     Get_Line (buffer, iLength)
     return buffer (buffer'First .. iLength);
  end InputString;

begin
   loop
      declare
         something : String := InputString;
      begin
         exit when something = "";
         Put_Line (something);
      end;
   end loop;
end everything;


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Alle Kinder stehen am Abgrund, nur nicht Peter, der ging noch'n Meter.



  reply	other threads:[~2005-01-29  9:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-29  8:55 Input a string (again) Stefan Merwitz
2005-01-29  9:53 ` Adrian Knoth [this message]
2005-01-29 12:51 ` Stefan Merwitz
2005-01-29 21:03 ` tmoran
replies disabled

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