有没有办法接受用户输入,无论是字符还是无界字符串,并将其转换为小写?
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);
我的输入:如果我输入BLUE
,put_line(N);
将返回blue@�hw�
答案 0 :(得分:1)
对于Character
和固定长度String
,有Ada.Characters.Handling.To_Lower
RM A.3.2
此外,Wide_Character
和Wide_String
中的Wide_Wide_Character
,Wide_Wide_String
,Ada.Wide_Characters.Handling
和Ada.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;