AQA · GCSE · Computer Science
Course version: 8525 · Version from Sept 2020
String handling operations in a programming language: length
The length operation returns the number of characters in a string, including spaces and punctuation.
Checked against the AQA 8525 specification (opens in a new tab) on .
- Point 1 of 11
Study notes
From the checked teaching notes for this specification point.
The idea
The length operation returns the number of characters in a string, including spaces and punctuation. In AQA 8525 pseudocode and most languages you apply it to a string variable, for example word ← "computer" then length(word) gives 8. Teach learners to count every character, not just letters: "hello world" has 11 characters because the space counts. Note that length returns an integer, so it can be compared, stored or used in a loop. Distinguish it from indexing, which returns a single character at a position. A common exam task asks for the output of a length expression or the value stored after assignment. Learners should trace the string character by character and state the integer result.
What earns the marks
- States that length returns the number of characters in the string as an integer.
- Counts spaces and punctuation as characters, e.g. "hello world" has 11 characters.
- Applies length to a named string variable and gives the correct integer for the given value.
- Distinguishes length (whole-string count) from position/indexing (single character).
Common mistakes and how to put them right
Counting only letters and ignoring spaces.
Put it right: Is to count every character including spaces and punctuation.
Confusing length with the position of the last character.
Put it right: Is that length is a count, so a string of 8 characters has length 8.
Treating length as returning a character.
Put it right: Is that it returns an integer count.
Exam tips
- Trace the string one character at a time, numbering each character to avoid miscounting.
- Write the integer answer clearly and check whether spaces are present before finalising.
- If asked for output, give the value only, not the expression.
Try the lesson
The start of the String handling operations in a programming language: length lesson, made from checked teaching notes for this specification point.
Have a go first
A program stores the string "computer" in a variable. What value does the length operation return for this string?
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of String handling operations in a programming language: length
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge