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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx16.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: array of string References: <3ffbdc6a-e767-4de1-922f-c9c1ec748f4d@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1412384840 68.145.219.148 (Sat, 04 Oct 2014 01:07:20 UTC) NNTP-Posting-Date: Sat, 04 Oct 2014 01:07:20 UTC Date: Fri, 03 Oct 2014 19:07:21 -0600 X-Received-Bytes: 2724 X-Received-Body-CRC: 2107383854 X-Original-Bytes: 2642 Xref: number.nntp.giganews.com comp.lang.ada:189364 Date: 2014-10-03T19:07:21-06:00 List-Id: On 2014-10-03 6:50 PM, Jerry wrote: > 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 > Some other options include; 1. Create an array type of access to string eg. type String_Array is array (Natural range <>) of access constant String; S1 : aliased constant String := "Toronto"; S2 : aliased constant String := "London"; S : String_Array := (1 => S1'Access, 2 => S2'Access); 2. You could use an indefinite container, such as an indefinite vector. eg. package S_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type => Natural, Element_Type => String); S_Vector : S_Vectors.Vector; ... S_Vector.Append ("Toronto"); S_Vector.Append ("London");