第一个字符大写其他小写文字
属性 Image
将枚举文字的所有字符都大写。函数 Case_Rule_For_Names
对第一个字符应用大写,并使其余为小写。
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
procedure Main is
type Fruit is (Banana, Pear, Orange, Melon);
function Case_Rule_For_Names (Item : String) return String is
begin
return Translate (Item (Item'First .. Item'First), Upper_Case_Map) & Translate (Item (Item'First + 1 .. Item'Last), Lower_Case_Map);
end;
begin
for I in Fruit loop
Put (Case_Rule_For_Names (Fruit'Image (I)));
New_Line;
end loop;
end;
结果
Banana
Pear
Orange
Melon