My question is rather simple, as Google has let me down. How do I convert an unbounded string to an integer?
If the string was bounded, I could do this: I : Integer := Integer'Value("613");
However, my string is unbounded, and Ada throws this error:
expected type "Standard.String"
found private type "Ada.Strings.Unbounded.Unbounded_String"
Is what I want to do possible?
You just have to do the intermediate conversion:
I : Integer := Integer'Value (To_String (T));
Here is a full test program:
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
T : Unbounded_String := To_Unbounded_String ("613");
I : Integer := Integer'Value (To_String (T));
begin
Put_Line (I'Image);
end Main;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With