comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry <lanceboyle@qwest.net>
Subject: Re: array of string
Date: Fri, 3 Oct 2014 17:50:44 -0700 (PDT)
Date: 2014-10-03T17:50:44-07:00	[thread overview]
Message-ID: <a192026a-1509-4e92-81b6-c021cb615a95@googlegroups.com> (raw)
In-Reply-To: <3ffbdc6a-e767-4de1-922f-c9c1ec748f4d@googlegroups.com>

On Friday, October 3, 2014 4:29:15 PM UTC-7, Stribor40 wrote:
> is there way to declare array of strings to contain something like this..
> 
> a(1)="london"
> 
> a(2)""toronto"
> 
> how would i create this?

The two examples you give, london and toronto, are of different lengths. The elememts of an array have to be the same (or compatible *) type(s), so you would have to make the strings the same length and then waste some of the length for shorter names, and hope that you have declared the string length long enough for your longest city name.

A better way is to make an array of unbounded strings whereby Ada things each element of the array is the same (an unbounded string) but yet unbounded strings can be of any length. The only thing you'll have to watch out for is that it is likely that other places will expect to see string, not unbounded string, for example, Put. This is easy as Ada provides conversion functions between strings and unbounded strings.

When I was first learning Ada (still am, really), learning about the three different kinds of strings was one of the most useful things to know. Another was to understand subtypes *.

Jerry


  reply	other threads:[~2014-10-04  0:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-03 23:29 array of string Stribor40
2014-10-04  0:50 ` Jerry [this message]
2014-10-04  1:07   ` Brad Moore
2014-10-04  1:19   ` Stribor40
2014-10-04  1:29     ` Stribor40
2014-10-04  2:01       ` Stribor40
2014-10-04  7:14       ` Simon Wright
2014-10-04  8:32       ` Dmitry A. Kazakov
2014-10-04 14:15         ` AdaMagica
2014-10-04 15:20           ` Dmitry A. Kazakov
2014-10-06 16:58             ` Adam Beneschan
2014-10-04  3:09     ` Shark8
2014-10-04  5:33     ` Brad Moore
2014-10-07  1:06 ` brbarkstrom
2014-10-07 16:06   ` Use of bounded strings? (Was: array of string) Jacob Sparre Andersen
2014-10-07  2:08 ` array of string Jerry
2014-10-07 16:49 ` brbarkstrom
replies disabled

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