设计一个字符大小写转换程序。

2024-12-29 22:32:01
推荐回答(1个)
回答1:

// Delphi语言
function Convert(const Source: String): String;
var
I: Word;
begin
Result := Source;
for I:=1 to Length(Source) do
begin
if(Result[I] in ['a'..'z']) then Dec(Result[I], 32)
else if(Result[I] in ['A'..'Z']) then Inc(Result[I], 32);
end;
end;

// C语言(单片机)
void Convert(uchar *Source, uchar *Result, uchar ucLength)
{
uchar * data P=Source+(ucLength);

while(Source!=P)
{
*Result = *Source++;
if((*Result>='a')&&(*Result<='z')) *Result -= 32;
else if((*Result>='A')&&(*Result<='Z')) *Result += 32;
Result++;
}
}