From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: How to initiate part of a string?
Date: 1998/08/26
Date: 1998-08-26T00:00:00+00:00 [thread overview]
Message-ID: <EACHUS.98Aug26113416@spectre.mitre.org> (raw)
In-Reply-To: 35e3675e.37587430@SantaClara01.news.InterNex.Net
In article <35e3675e.37587430@SantaClara01.news.InterNex.Net> tmoran@bix.com (Tom Moran) writes:
Quite so, it should have been
Txt : String(1 .. 100) := (1 .. 27=>' ') & "abcd" & (32 .. 100=>' ');
That actually is not the same thing. The bounds of "abcd" are
1..4, but the catenation preserves the lower bound of the leftmost
entry. So:
Txt : String(1 .. 100) := (1 .. 27=>' ') & "abcd" & (1 .. 69=>' ');
is equivalent, except for expository purposes. To create an aggregate
that can initialize the string write:
Txt2: String(1..100) := (1..27 => ' ', 28 => 'a', 29 => 'b',
30 => 'c', 31 => 'd', 32..100 => ' ');
Painful, but at least in this case you get better bounds info. Better
still try:
Txt3: String(1..100) := (28 => 'a', 29 => 'b', 30 => 'c', 31 => 'd',
others => ' ');
Of course, reality is that if you really need to do something like
this, you would, I hope, use the standard libraries:
with Ada.Strings.Fixed;use Ada.Strings.Fixed;
...
Txt4: String(1..100) := Overwrite(Source => String'(1..100 => ' '),
Position => 28,
New_Item => "abcd");
Now finally, I can answer the original question. Note that Source
argument above was provided as an aggregate, I could also have
written, using the "*" function in Ada.Strings.Fixed:
Txt5: String(1..100) := Overwrite(Source => 100 * ' ',
Position => 28,
New_Item => "abcd");
or if you really insist on partial initialization:
Junk: String(1..100); -- uninitialized
Txt6: String(1..100) := Overwrite(Source => Junk,
Position => 28,
New_Item => "abcd");
--
Robert I. Eachus
with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...
next prev parent reply other threads:[~1998-08-26 0:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-24 0:00 How to initiate part of a string? Hans Marqvardsen
1998-08-25 0:00 ` Tom Moran
1998-08-25 0:00 ` Samuel Tardieu
1998-08-26 0:00 ` Tom Moran
1998-08-26 0:00 ` Robert I. Eachus [this message]
1998-08-26 0:00 ` Tom Moran
1998-09-24 0:00 ` Bob Fletcher
1998-09-24 0:00 ` Tom Moran
1998-09-25 0:00 ` dewarr
1998-09-29 0:00 ` Aidan Skinner
1998-09-19 0:00 ` dewarr
1998-08-25 0:00 ` Mark A Biggar
1998-08-26 0:00 ` Frank Ecke
1998-08-26 0:00 ` Robert I. Eachus
1998-08-26 0:00 ` Mats Weber
1998-08-26 0:00 ` Frank Ecke
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox