SUBSTRING function
SUBSTRING(string, start, length) returns length characters beginning at position start. Position 1 is the first character, so this returns "Happy".
Understanding SUBSTRING function in IGCSE Computer Science Paper 2
What it does: Start at position 1 (the first character) with a length of 3 to get 3 characters, then assign the result with ←. Cambridge pseudocode counts string positions from 1, so SUBSTRING(Word, 1, 1) gives the first character. The last value is the length. It says how many characters to return, not where to stop. A length of 1 returns a single character. A length of 0 would return nothing. SUBSTRING only returns a copy of part of the string. To keep the result you must assign it to a variable. "Days" starts at position 7 and is 4 characters long, so the correct call is SUBSTRING("Happy Days", 7, 4).
Common mistakes: In SUBSTRING the first character is at position 1, so a start of 0 is invalid. The line should be First ← SUBSTRING(Word, 1, 5), which gives "Happy". SUBSTRING needs three arguments: the string, the start and the length. The length is missing. It should be SUBSTRING("Cloud", 3, 1) to pick out the single character "o".
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 37–46) and word search (Modules 27–46).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
SUBSTRING("Happy Days", 1, 5)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →