Search code examples
delphidelphi-7

Need to change capital character to a small one in Delphi


I have this string where I need to make some characters capital so I use that UpCase command... But what if I need to make small character from capital one? What do I use in that case?


Solution

  • UpCase is not locale aware and only handles the 26 letters of the English language. If that is really all you need then you can create equivalent LoCase functions like this:

    function LoCase(ch: AnsiChar): AnsiChar; overload;
    begin
      case ch of
      'A'..'Z':
        Result := AnsiChar(Ord(ch) + Ord('a')-Ord('A'));
      else
        Result := ch;
      end;
    end;
    
    function LoCase(ch: WideChar): WideChar; overload;
    begin
      case ch of
      'A'..'Z':
        Result := WideChar(Ord(ch) + Ord('a')-Ord('A'));
      else
        Result := ch;
      end;
    end;