Ada で整数を文字に変換する方法はありますか?
元:
TempInt := 1;
InGrid(RowIndex, ColumnIndex) := (ToCharacter(TempInt)); --This will be used to input a character value from an integer into an array of characters.
Ada の Integer->Character 変換用の「ToCharacter」はありますか?
Ada で整数を文字に変換する方法はありますか?
元:
TempInt := 1;
InGrid(RowIndex, ColumnIndex) := (ToCharacter(TempInt)); --This will be used to input a character value from an integer into an array of characters.
Ada の Integer->Character 変換用の「ToCharacter」はありますか?
ASCII コードに変換するか、整数値を文字列として表示するかによって異なります。
ここに両方のケースの例があります
with Ada.Text_IO; use Ada.Text_IO;
procedure test is
temp_var : Integer := 97;
begin
Put_Line ("Value of the integer shown as string: " & Integer'Image(temp_var));
Put_Line ("Value of the integer shown as the ascii code: " & Character'Val(temp_var));
end test;
結果は
文字列として表示される整数の値: 97
アスキー コードとして示される整数の値: a
LRM の附属書 K に目を通すことを強くお勧めします。これは、おそらくあなたが必要としているものと、まだ必要だと気付いていない他の多くの機能をカバーしているためです。
そこに関連するものの中で:
整数 (Foo) をその整数の値の印刷可能な文字列表現に変換する:
Integer'image(Foo)
整数 (0 から 255 までの Foo) を、その値で表される ASCII 文字に変換します。
Character'Val(Foo)
上記の例では、値Foo
が 65 の場合、最初の行は文字列を返し、"65"
2行目は文字を返し'A'
ます。