第一個字元大寫其他小寫文字

屬性 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