README.md

December 5, 2022 · View on GitHub

Change String To Proper Case

Description

I may be reinventing the wheel here, but so far I have yet to find a built in Delphi function that will convert a string to proper case. I found this code somewhere on the web a while back, lost it, and managed to recreate it last night.

More Info

Submitted On
Bybleh
LevelBeginner
User Rating5.0 (10 globes from 2 users)
CompatibilityDelphi 5
CategoryString Manipulation
WorldDelphi
Archive File

Source Code

NOTE:Make sure to add "StrUtils" to your Uses section

function properCase(sBuffer: string):string;
var
    iLen, iIndex: integer;
begin
    iLen := Length(sBuffer);
    sBuffer:= Uppercase(MidStr(sBuffer, 1, 1)) + Lowercase(MidStr(sBuffer,2, iLen));

    for iIndex := 0 to iLen do
    begin
      if MidStr(sBuffer, iIndex, 1) = ' ' then
          sBuffer := MidStr(sBuffer, 0, iIndex) + Uppercase(MidStr(sBuffer, iIndex + 1, 1)) + Lowercase(MidStr(sBuffer, iIndex + 2, iLen));
    end;

    Result := sBuffer;

end;