Strings in Ada are tricky, and so too are characters – or at least they can be if you don’t use the right function. Remember, ADA is huge. There are a bunch of functions that will turn a string into an integer. The first of these is Integer’Value. Given the declaration:
str : string(1..9); num : integer;
Then the numeric version of the string stored in str, can be realized using this function:
num := Integer'Value(str);
Now to get the individual digits requires peeling them off one by one, which is somewhat tedious. Another way of doing this is using a function which just returns the ASCII value of a character.
for i in 1..9 loop num := Character'Pos(str(i)) - 48; put(num); end loop;
Now, as shown in the example, simply subtracting 48 from the ASCII value gives the actual numeric value.