comp.lang.ada
 help / color / mirror / Atom feed
From: brbarkstrom@gmail.com
Subject: Re: array of string
Date: Tue, 7 Oct 2014 09:49:43 -0700 (PDT)
Date: 2014-10-07T09:49:43-07:00	[thread overview]
Message-ID: <9950a796-253a-4799-ade4-9997d05a9f34@googlegroups.com> (raw)
In-Reply-To: <3ffbdc6a-e767-4de1-922f-c9c1ec748f4d@googlegroups.com>

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?

Constantly.  It's a habit now.  One advantage is the Bounded_Strings
library in the ARM.  It has functions for appending strings, extracting slices,
obtaining single characters, and so on.  I've created a package I call
Common_Defs.ads that lets me have a moderately long string (256 characters)
and a very long one (5000 characters).  Note also that the Bounded_String
library throws an exception if you try to stuff too many characters into
the string.  That provides a reasonable way to filter out strings that could
cause buffer overflows in Web page text inputs.

Here's the code:

with Ada.Characters.Latin_1;
with Ada.Strings;
with Ada.Strings.Bounded;
with Ada.Numerics;
with Ada.Numerics.generic_elementary_functions;

package Common_Defs is
  ------------------------------------------------------------------------------
  -- Generic Packages
  ------------------------------------------------------------------------------
  subtype real        is long_float;
  package Usr_Math    is new
                        Ada.Numerics.generic_elementary_functions(real);
  Std_Vstring_Length  : constant :=  256;
  package VString     is new
                        Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length);
  Long_Vstring_Lngth  : constant := 5000;
  package Long_Vstring is new
                        Ada.Strings.Bounded.Generic_Bounded_Length(Long_Vstring_Lngth);
  ------------------------------------------------------------------------------
  -- Constant
  ------------------------------------------------------------------------------
   TAB                         : constant Character := Ada.Characters.Latin_1.HT;
end Common_Defs;

This package spec lets me create long_floats and bring along the appropriate
math functions in one fell swoop.  If using the compiler default on long_floats
worries you, you can define the numerical type you want and embed it in this
kind of spec.  The reason for having the TAB character is if you want to 
create TAB-delimited text files that you can feed into spreadsheets.  If you
do the usual 

with Common_Defs; use Common_Defs;

then you can just use Put(TAB) (or Put(Output_File, TAB)) in Text_IO 
interactions.

Bruce B.

      parent reply	other threads:[~2014-10-07 16:49 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
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 [this message]
replies disabled

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