Ada - 是否有一个函数可以使字符或无界字符串小写?

时间:2015-03-02 20:02:31

标签: ada

有没有办法接受用户输入,无论是字符还是无界字符串,并将其转换为小写?

newLine, N: unbounded_string;
M: string(1..26);
len: integer;

new_line; new_line;    
put("What is your favorite color?");
new_line;
put("Answer:");
get_line(newLine);
get_line(M,len);
N := to_unbounded_string(to_lower(M));
put_line(N);

我的输入:如果我输入BLUEput_line(N);将返回blue@�hw�

2 个答案:

答案 0 :(得分:1)

对于Character和固定长度String,有Ada.Characters.Handling.To_Lower RM A.3.2

此外,Wide_CharacterWide_String中的Wide_Wide_CharacterWide_Wide_StringAda.Wide_Characters.HandlingAda.Wide_Wide_Characters.Handling存在类似的功能

答案 1 :(得分:0)

with Ada.Strings;
with Ada.Strings.Maps.Constants;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;

procedure Change_Case is

   S : Ada.Strings.Unbounded.Unbounded_String;

begin
   Ada.Text_IO.Put_Line("Enter a string: ");
   S := Ada.Strings.Unbounded.To_Unbounded_String(Ada.Text_IO.Get_Line);
   Ada.Text_IO.Unbounded_IO.Put_Line(S);
   Ada.Strings.Unbounded.Translate(S, Ada.Strings.Maps.Constants.Lower_Case_Map);
   Ada.Text_IO.Unbounded_IO.Put_Line(S);
   Ada.Strings.Unbounded.Translate(S, Ada.Strings.Maps.Constants.Upper_Case_Map);
end Change_Case;