3 ms·
Hmm? Ada uses the apostrophe for character literals and to introduce attributes. Strings are arrays; indexing uses the same `array[index]` syntax as any other a
by _kst_ 12y ago
Hmm? Ada uses the apostrophe for character literals and to introduce attributes. Strings are arrays; indexing uses the same `array[index]` syntax as any other array.
S: constant String := "Hello";
H: constant Character := S(1);
- agumonkey 12y agoTrue, I was thinking about type conversion from String to Character, IIRC you have to use ' operator, something like my_string'first (not sure, I needed it 10 years ago), otherwise my_string(1) gives a String of length one, not the first Character.
- attackcrow 12y agoDepends on how the array is defined. Ada allows you to have any discrete type as your array indices, so to get the first element of an array, you need to use my_string(my_string'first).