From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Empty String confusion; Positive and Natural Date: Tue, 30 Nov 2021 10:34:56 +0200 Organization: Tidorum Ltd Message-ID: References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net aqIKDf7UfbkDE3Ze+FWzoQ9OljRS20jozpKbR6OPwXh5HyLMrH Cancel-Lock: sha1:sT+APXlOFw3L7/riESajLvXGvrQ= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63169 List-Id: On 2021-11-30 0:50, Kevin Chadwick wrote: >> It would clarify your question if you would show the declaration of that >> record type. Does it use the String type, or the Unbounded_String type? > > Hopefully I will have a doh moment when I get into the office in the > morning and post code. I am getting a range check exception when I > assign "" to a standard.String Although Standard.String is an unconstrained array type (that is, its index range is defined as "Positive range <>"), every object of this type is constrained to a fixed length, set when the object is created. So if you have, for example: S : String (1 .. 10); then S'Length is always 10. If you try to assign to S a string of a different length, for example "", you will get an exception because the lengths do not match. If you want a string object that is flexible in terms of length, you should use the type Ada.Strings.Unbounded.Unbounded_String, or make an instance of Ada.Strings.Bounded.Bounded_String with a suitable maximum length. Or you could use a fixed-length string but always pad it with blanks (or whatever) up to the fixed length -- see Ada.Strings.Fixed for several useful operations on such strings. Depends on what you want...