Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert unbounded string to integer Ada

Tags:

string

ada

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?

like image 760
MortalMan Avatar asked Sep 05 '26 12:09

MortalMan


1 Answers

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;
like image 65
raph.amiard Avatar answered Sep 07 '26 05:09

raph.amiard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!