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
显示为 ascii 代码的整数值:a
我强烈建议您查看LRM 的 Annex K,因为它可能涵盖了您想要的内容,以及许多您尚未意识到自己想要的其他好东西。
在其中的相关内容中:
将整数 (Foo) 转换为该整数值的可打印字符串表示形式:
Integer'image(Foo)
将整数(Foo,介于 0 和 255 之间)转换为由该值表示的 ASCII 字符:
Character'Val(Foo)
在上面的例子中,如果 in 的Foo
值为 65,那么第一行将返回 string "65"
,而第二行将返回 character 'A'
。