LearnStanmorephysics

Grade 10 · Delphi Foundations

First steps with strings

Grade 10 · Loops & first strings · Lesson and coding task · about 12 minutes

Open this task in the Delphi workspace →

Strings are just rows of characters — and you can visit them one character at a time. Two essentials:

Length(sName)      // how many characters
sName[3]           // the 3rd character (counting starts at 1!)

Combine them with a FOR loop and you can take any string apart:

for i := 1 to Length(sName) do
  memOutput.Lines.Add(sName[i]);   // one character per line

UpperCase(s) and LowerCase(s) convert a whole string. (Grade 11 goes much deeper — Copy, Pos, Delete and friends. This is the warm-up.)

Your task

Take the name in the edit box, SHOUT it into the memo, report its length on the label, then spell it vertically — one letter per line.

What you will do

Hints
  1. UpperCase(sName) + '!' makes the shout.
  2. Length gives an Integer — IntToStr it into the label text.
  3. for i := 1 to Length(sName) do memOutput.Lines.Add(sName[i]);
Model solution
procedure TfrmName.btnShoutClick(Sender: TObject);
var
  sName : String;
  i : Integer;
begin
  sName := edtName.Text;
  memOutput.Lines.Add(UpperCase(sName) + '!');
  lblInfo.Caption := 'Your name has ' + IntToStr(Length(sName)) + ' letters';
  for i := 1 to Length(sName) do
    memOutput.Lines.Add(sName[i]);
end;

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.