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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.189.97 with SMTP id gh1mr267845pac.43.1412644015122; Mon, 06 Oct 2014 18:06:55 -0700 (PDT) X-Received: by 10.140.104.176 with SMTP id a45mr294588qgf.5.1412644015073; Mon, 06 Oct 2014 18:06:55 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!uq10no5284867igb.0!news-out.google.com!q8ni43qal.1!nntp.google.com!s7no999954qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 6 Oct 2014 18:06:54 -0700 (PDT) In-Reply-To: <3ffbdc6a-e767-4de1-922f-c9c1ec748f4d@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.111.113.147; posting-account=Ies7ywoAAACcdHZMiIRy0M84lcJvfxwg NNTP-Posting-Host: 50.111.113.147 References: <3ffbdc6a-e767-4de1-922f-c9c1ec748f4d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <570672e5-a8ba-407c-a04a-9bf4cc723708@googlegroups.com> Subject: Re: array of string From: brbarkstrom@gmail.com Injection-Date: Tue, 07 Oct 2014 01:06:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:22164 Date: 2014-10-06T18:06:54-07:00 List-Id: On Friday, October 3, 2014 7:29:15 PM UTC-4, 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? You could also create an array of Bounded_Strings. When you set up such an array, you can specify the maximum size. Then when you assign a particular array element, you use the Bounded_Strings package functions to assign a string to the array. In other words, you can write Std_Vstring_Length : constant := 256; package Vstring is new Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length); Then you should be able to define Max_Array_Size : constant := 10; -- or whatever the number of strings you want Bounded_String_Array : array (1 .. Max_Array_Size) of Vstring.Bounded_String; later, you can do things like Bounded_String_Array(1) := Vstring.To_Bounded_String("london"); Bounded_String_Array(2) := Vstring.To_Bounded_String("toronto"); If you want to print the strings, you can do things like Text_IO.Put(Vstring.To_String(Bounded_String_Array(1))); which should output just london while Text_IO.Put_Line(Vstring.To_String(Bounded_String_Array(2))); would ouput toronto on a single line. There are a number of useful functions, including Slice and Element in the Bounded_Strings package. You can even use Direct_IO to save the elements of the array Bounded_String_Array so you can retrieve them by doing package Bounded_String_DIO is new Direct_IO(Bounded_String_Array); use Bounded_String_DIO; Then you can do things like Bounded_String_DIO.Write(File => Bounded_String_DIO_File, Item => Bounded_String_Array(4), To => Bounded_String.Positive_Count(4)); and read it with Bounded_String_DIO.Read(File => Bounded_String_DIO_File, Item => Selected_Bounded_String, From => Bounded_String.Positive_Count(4)); which will read the Bounded_String_Array element 4 into Selected_Bounded_String : Vstring.Bounded_String; Hope this helps. Bruce B.