Reputation: 115
I am trying to convert small strings into their respective ascii decimal values. Like converting the string "Ag" to "065103".
I tried using
integer_variable : Integer := Integer'Value(Ag);
but that gives me constraint error: bad input for 'Value: "Ag".
Is there something else I can use to make this work? Could I just use enumeration?
Upvotes: 2
Views: 886
Reputation: 881
Strings in Ada are arrays of Characters, thus if you want to convert String to Integer values you have to do this for each Character separately, by taking its position in enumeration (as suggested in the comment to your question). In your example it could be:
integer_variable1 : Natural := Character'Pos('A');
integer_variable2 : Natural := Character'Pos('g');
Upvotes: 2