Name

UpCase Function

Syntax

function UpCase(C: Char): Char;

Description

The UpCase function converts an ASCII character to uppercase. If C is not a lowercase character, UpCase returns C. UpCase is a real function.

Tips and Tricks

  • UpCase does not handle international characters—it handles only “a” through “z”.

  • Delphi does not have a corresponding DownCase function.

Example

function DownCase(Ch: Char): Char;
begin
  if Ch in ['A'..'Z'] then
    Result := Chr(Ord(Ch) - Ord('A') + Ord('a'))
  else
    Result := Ch;
end;

// Convert an identifier to canonical form, i.e., initial uppercase
// character followed by all lower case characters.
function Canonical(const S: string): string;
var
  I: Integer;
begin
  SetLength(Result, Length(S));
  if Length(S) > 0 then
    Result[1] := UpCase(S[1]);
  for I := 2 to Length(S) do
    Result[I] := DownCase(S[I]);
end;

See Also

AnsiChar Type, Char Type, WideChar Type

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.