Substring extracts a section of a string.
SUBSTRING('Computer Science', 0, 7) # 'Computer'
Conventions vary between languages — some take (start, length), others (start, end). The specification simply requires that you can use substring, so an exam question will always make its convention clear, either by stating it or by showing a worked example. Read that carefully before answering.
Common uses
# First character (e.g. an initial)
initial ← SUBSTRING(firstName, 0, 1)
# Extract the year from a date string 'DD/MM/YYYY'
year ← SUBSTRING(dateOfBirth, 6, 4)
# Extract the area code from a phone number
areaCode ← SUBSTRING(phone, 0, 5)
# Split a postcode
outward ← SUBSTRING(postcode, 0, 4)
Building a username — the classic exam task
"Create a username from the first 3 letters of the surname plus the first initial."
surname ← 'Patel'
firstName ← 'Amina'
username ← SUBSTRING(surname, 0, 3) + SUBSTRING(firstName, 0, 1)
# 'Pat' + 'A' = 'PatA'
This single example uses substring and concatenation together, which is exactly how the subtopic is examined.
Guarding against a short string
IF LEN(surname) ≥ 3 THEN
code ← SUBSTRING(surname, 0, 3)
ELSE
code ← surname
ENDIF
Asking for three characters from a two-character surname causes an error, so a robust program checks the length first. Noticing that is a genuine AO3 point.
AQA tip. When a question gives a substring example, use its convention exactly — do not substitute the one from your taught language.