From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 10:34:56 +0200 [thread overview]
Message-ID: <j0m61gF1p4jU1@mid.individual.net> (raw)
In-Reply-To: <bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
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...
next prev parent reply other threads:[~2021-11-30 8:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-29 17:34 Empty String confusion; Positive and Natural Kevin Chadwick
2021-11-29 18:05 ` Jeffrey R.Carter
2021-11-29 19:19 ` Niklas Holsti
2021-11-29 22:50 ` Kevin Chadwick
2021-11-30 8:29 ` Simon Wright
2021-11-30 8:34 ` Niklas Holsti [this message]
2021-11-30 10:00 ` Jeffrey R.Carter
2021-11-30 12:17 ` Kevin Chadwick
2021-11-30 12:54 ` J-P. Rosen
2021-11-30 13:12 ` Kevin Chadwick
2021-11-30 7:40 ` ldries46
2021-11-30 8:21 ` Simon Wright
2021-11-30 12:39 ` ldries46
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox