Re: STRING length



markww writes:
Thanks Georg, that looks to be exactly what I need. I do have a problem
'#including', or, 'withing' rather unbounded string.
Now the head of my source file looks like:

with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded;
use Ada.Text_IO, Ada.Integer_Text_IO;

which is alright but as soon as I try:

use Ada.Strings.Unbounded;

the compiler gives me a bunch of errors, it seems to conflict with
Text_IO / Integer_Text_IO? Seems like all my previous calls to Put()
now became invalid. I'm not familiar with Ada but with C++ and
understand namespace collisions, is the same thing going on here?

In theory, a use clause may make subprogram calls ambiguous and thus
illegal, but I don't think that's your problem here, because
Ada.Strings.Unbounded does not contain any Put subprogram that might
collide with those in Ada.Text_IO or Ada.Integer_Text_IO.

Instead, I think that your problem stems from the the use clause
making the following operators directly visible (from ARM A.4.5):

15. function "&" (Left, Right : in Unbounded_String)
return Unbounded_String;

16. function "&" (Left : in Unbounded_String; Right : in String)
return Unbounded_String;

17. function "&" (Left : in String; Right : in Unbounded_String)
return Unbounded_String;

18. function "&" (Left : in Unbounded_String; Right : in Character)
return Unbounded_String;

19. function "&" (Left : in Character; Right : in Unbounded_String)
return Unbounded_String;

so now you're constructing unbounded strings by concatenating strings
and unbounded strings, and passing them to Ada.Text_IO.Put, which is
of course illegal.

You should convert the unbounded strings to regular strings before
passing them to Ada.Text_IO.Put, like so:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Foo is
S : Unbounded_String := "Hello" & To_Unbounded_String (", world!");
-- calls Ada.Strings.Unbounded."&" which is directly visible
begin
Ada.Text_IO.Put (To_String (S)); -- convert and print
end Foo;

HTH

--
Ludovic Brenta.
.