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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ae9506fd4dcf7090 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-10 10:46:22 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!HSNX.atgi.net!cyclone-sf.pbi.net!151.164.30.35!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!uunet!dfw.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Concatenation and Characters User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Thu, 10 Oct 2002 17:45:42 GMT Content-Type: text/plain; charset=us-ascii References: <12hp9.796$_u6.380@nwrddc01.gnilink.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:29682 Date: 2002-10-10T17:45:42+00:00 List-Id: "Justin Birtwell" writes: > This is what I don't understand! How can you declare a string variable when > you don't know before hand what the string is going to be? Type String is fixed-length, meaning that you have to know the exact length when you create a String object. (But different Strings can be different lengths.) Yes, this is somewhat restrictive. One thing you can do is leave the bounds off. That's allowed if the String has an initial value, and the String is then exactly as long as that value (and its length never changes). Like this: S: String := "ABCD"; T: String := "EF"; U: String := S & T; -- U has bounds 1..6. Note that you can write functions that return "String" -- the length of the String is determined when the function returns, and can be different each time it's called. And you can use a call to initialize a variable or constant: X: constant String := Func(...); In fact, "&" is really just a built-in function that works this way. If you really want strings whose length changes over time, you should use the Bounded or Unbounded_Strings packages. Unbounded_Strings is the most flexible. Your other question was: > Chars:array range(1..3) of Characters:=('a','b','c'); > > How can I convert it to a string? > > Put(Chars) --Compile Error:Invalid param list! You can use a type conversion, as in: Put(String(Chars)); There are lots of complicated rules about what types may be converted to what other types -- look up "type conversion" in the RM or some textbook. By the way, you could have used a string_literal above: Chars: array (1..3) of Character := "abc"; String_literals are not specific to type String; they work for any "string type". A string type is any one-dimensional array of a character type. A character type is any enumeration type that has character literals -- although you normally only need the predefined ones Character and Wide_Character. The (anonymous) type of Chars is a string type. Or, you could consider whether you really want Chars to have a separate type -- you could say: Chars: String := "abc"; or Chars: constant String := "abc"; if Chars never changes. Then you can "Put(Chars);". - Bob