comp.lang.ada
 help / color / mirror / Atom feed
* Array Of Constant Strings?
@ 2003-02-14  2:58 Dr Nancy's Sweetie
  2003-02-14  4:28 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Dr Nancy's Sweetie @ 2003-02-14  2:58 UTC (permalink / raw)


Maybe I'm just doing this wrong, but the only solution I can see
looks unreasaonbly verbose.

What I want is to set up an array of constant strings, all the same
length.  I tried using Ada.Strings.Bounded, with something like
this:

   package Name_Package is new Generic_Bounded_Length(7);

   type Name_String is new Digit_Package.Bounded_String;

   Name_List : constant array(1..26) of Name_String :=
       ("Anthony", "Barbara", "Claudia", "Deborah" "Elliott",
         .... and so on.

But it complains that:

    expected private type "Name_String" defined at line 26
    found a string type

(I sorta expected this to work because a similar initialization is
possible with Integers.)

I can throw in explicit conversion functions:

   function To_Name_String(Source: String;
                           Drop:   Truncation := Right)
                           return Name_String renames
     Name_Package.To_Bounded_String;


and then make the Name_List this way:

   Name_List : constant array(1..26) of Name_String :=
       (To_Name_String("Anthony"),
        To_Name_String("Barbara"),
        To_Name_String("Claudia"),
        ... and so on.

But that seems really klunky, somehow; like there ought to be a better
way to do this than repeating "To_Name_String" dozens of times.


It won't let me just say:

   Name_List : constant array(1..26) of String :=
       ("Anthony", "Barbara", "Claudia", "Deborah" "Elliott",
         .... and so on.

because, as it informs me,

    unconstrained element type in array declaration


So is there some better way to do this?  I primarily speak C, so I'm
used to (and maybe spoiled by 8-) a little type flexibility which isn't
here to be had.  The strings don't have to be bounded: the input is
guaranteed to be exactly a given length, so fixed-length strings would
be fine.  But I couldn't get that to work either.

My situation is that I have a bunch of strings, all the same length,
and they'll never ever change.  All I want to do is stick them in an
array so later I can read in a strings and see if it matches one on
my list, and if so in what position.

What's the "best" (for some definition of "best") way to do that?


Darren Provine ! kilroy@elvis.rowan.edu ! http://www.rowan.edu/~kilroy
"Many verbal attacks are part of someone's aim to establish their rank
 in a dominance hierarchy, the same sort of behavior common among
 nesting fowl." -- Daniel Mocsny



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2003-04-17 20:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-14  2:58 Array Of Constant Strings? Dr Nancy's Sweetie
2003-02-14  4:28 ` tmoran
2003-02-14  7:28 ` Dale Stanbrough
2003-02-14  7:47   ` tmoran
2003-02-14 10:06     ` Dale Stanbrough
     [not found] ` <19guh-2f4.ln1@beastie.ix.netcom.com>
2003-02-14 19:41   ` Jeffrey Carter
2003-02-14 20:38     ` tmoran
     [not found]     ` <e0q0i-n14.ln1@beastie.ix.netcom.com>
2003-02-15 22:28       ` Jeffrey Carter
2003-02-22 19:31     ` Robert A Duff
2003-04-14 18:43       ` Dr Nancy's Sweetie
2003-04-15 11:36         ` Georg Bauhaus
2003-04-15 13:40           ` Dr Nancy's Sweetie
2003-04-15 15:13             ` Georg Bauhaus
2003-04-16  2:17               ` Matthew Heaney
2003-04-16 16:35                 ` Chad R. Meiners
2003-04-16 21:03                 ` Georg Bauhaus
2003-04-17 17:53                   ` Robert A Duff
2003-04-17 20:34                     ` Georg Bauhaus

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