How to Capitalize Text

We write the words in the middle of the sentence in lowercase letters. Capitalizing is sometimes necessary to emphasize things. Any text (or string) can be converted to uppercase (capitalize). Here’s how…

Quick Tutorial

Create a new Application Project. Project -> New Project -> Application -> OK.

Drop a TMemo and a TButton in the form. Select the TMemo and set the Scrollbars property to ssAutoVertical. Set the Caption of the TButton to Capitalize it !. Double click the button. Then write the following:

1
2
3
4
5
6
procedure TForm1.Button1Click(Sender: TObject);
begin

  Memo1.Text := UpperCase(Memo1.Text);

end;

Run It

Press F9 (or Run -> Run). Enter some text in the memo and then click the button.

Concept

Well it’s easy! Just find out what you want to capitalize and then use the Uppercase() function to capitalize it. The function comes from sysutils unit.

For example,

1
2
3
4
5
6
7
8
9
10
uses
..., sysutils, ...;

...

begin

  Caption := Uppercase('John Doe');

end;

The above function will set the form’s caption as JOHN DOE.

So the syntax is:

1
2
3
function UpperCase(
  const s:
):;

Downloads

You can download the source code for the tutorial project and executable/EXE files from the links below: