comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: Newbie Questions about Get, Get_Line
Date: Sat, 30 Dec 2000 17:09:27 GMT
Date: 2000-12-30T17:09:27+00:00	[thread overview]
Message-ID: <92l4s4$hjb$1@nnrp1.deja.com> (raw)
In-Reply-To: k73r4toon9d6e0oi384t6240d32d7leohc@4ax.com

In article <k73r4toon9d6e0oi384t6240d32d7leohc@4ax.com>,
  gressett@iglobal.net wrote:

> What I would really find useful is a routine that could take a string
> variable and fill it with terminal input with the following
> properties:
>
> If the user input is shorter that the string variable, it will be
> padded with blanks.

Ewww. Why would you want that? Its soooo sloppy (not to mention
wasteful). Plus it would significantly complicate dealing with the
string later. If you want to insert that string in the middle of other
strings, how are you going to do it? Just using "&" on a slice won't do
the trick anymore, because you won't know the proper slice to use.

If you really want this behavior, you can always do a:
   Str := (others => ' ');
before the call, then ignore the return length. Better would be to use
the return length to do the fill:
   Str (Last+1..Str'Last) := (others => ' ');

> If the user input is longer than the string variable, the extra
> characters should be thrown away, never to be seen again.

There's nothing stopping you from writing a routine to do this yourself.
It would only be about 3 lines of code (although handling *any* length
would probably be a smidge more complicated, requiring a loop or
recursion). But if I were you, I'd try to work with what the language
gives me for a while. You should get used to Ada string handling before
you go trying to fight it.

Some have expressed a desire for a function that returns a
perfectly-sized string, instead of the string-buffer and length
interface. That would be more in keeping with the language (although you
could only use it in certain circumstances). For an example of how to do
that, see Martin Carlisle's entry on AdaPower at
http://www.adapower.com/lang/recstring.html

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com
http://www.deja.com/



  parent reply	other threads:[~2000-12-30 17:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-30  7:33 Newbie Questions about Get, Get_Line gressett
2000-12-30 14:13 ` Marin David Condic
2000-12-30 17:17   ` Ted Dennison
2000-12-30 17:25     ` Ted Dennison
2000-12-30 22:46     ` Marin David Condic
2000-12-30 23:12       ` Ted Dennison
2000-12-30 14:31 ` Jeff Creem
2000-12-30 17:09 ` Ted Dennison [this message]
2000-12-31  8:13   ` gressett
2000-12-31 15:50     ` Larry Kilgallen
2000-12-31 17:03     ` Robert Dewar
2000-12-31 17:47     ` Ted Dennison
2000-12-31 21:07     ` tmoran
2001-01-01  6:12       ` gressett
2001-01-01 17:45         ` Robert Dewar
2001-01-01 17:46         ` Robert Dewar
replies disabled

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