Spec & Goals 3 min
AQA Spec 3.2.8 · String handling operations
By the end of this lesson you can:
- Find the length of a string and extract a substring from it.
- Concatenate strings and convert their case to upper or lower.
- Convert between a character and its character code.
Warm-Up 5 min
Last lesson you read input and rolled dice. Today we slice, join and measure text.
Quick starter
The word 'ROBOT' is a string of characters.
How many characters does it contain, and what is its first character?
Reveal the answer
It has 5 characters. The first character is 'R'. Counting characters is what LEN does.
Key Concept — working with strings 14 min
A string is a sequence of characters, such as a name or a word.
The operations you must know
| Operation | Pseudo-code | What it does |
|---|---|---|
| Length | LEN(s) | The number of characters in s. |
| Substring | SUBSTRING(start, end, s) | Extract the characters from start to end. |
| Position | POSITION(s, char) | The index of the first char in s. |
| Concatenation | a + b | Join two strings into one. |
| Case conversion | STRING_TO_UPPER(s) | Convert to upper (or lower) case. |
| Character → code | CHAR_TO_CODE(c) | The ASCII/Unicode number for a character. |
| Code → character | CODE_TO_CHAR(n) | The character for a code number. |
Worked Example — building a username 12 min
Problem: from a first name and a surname, build a username = the first letter of the first name + the surname (in upper case), then report its length.
Use first ← 'Aisyah' and last ← 'Tan'. Expected username: 'ATAN'.
AQA pseudo-code
first ← 'Aisyah' last ← 'Tan' initial ← SUBSTRING(0, 0, first) username ← STRING_TO_UPPER(initial + last) OUTPUT username OUTPUT LEN(username)
The same in Python
first = "Aisyah" last = "Tan" initial = first[0] username = (initial + last).upper() print(username) print(len(username))
The output is ATAN then 4. To find the character code of the first letter you would use ord("A"), giving 65; chr(65) turns it back into "A".
Try It Yourself 12 min
Goal: Write a line of AQA pseudo-code that outputs the length of a string stored in word.
Hint: use LEN(word) inside an OUTPUT.
Goal: Write pseudo-code that joins town and state with a comma and a space between them, e.g. 'Ipoh, Perak'.
Hint: concatenate three parts: town, the text ', ', then state.
Goal: Write pseudo-code that inputs a full name, then outputs it in upper case together with its length.
📝 Exam Practice 10 min
Answer the way the examiner expects — the command word and the marks tell you how much to write.
State the output of LEN("ROBOT").
Mark scheme
5(1).
Write an expression that joins the strings first and last into one string, with a single space between them.
Mark scheme
- Concatenation of
firstandlastusing+(1). - A space
' 'joined in the middle, e.g.first + ' ' + last(1).
The string name ← 'ROBOT'. State the value of POSITION(name, 'B').
Mark scheme
2(1) — positions count from 0, so R=0, O=1, B=2.
The character code of 'A' is 65. Give the character with code 66.
Mark scheme
'B'(1) — the next code is the next letter.
Recap & Key Terms 3 min
A string is a sequence of characters. We measure it with LEN, cut it with SUBSTRING, find a character with POSITION, join strings by concatenation, change case, and convert between a character and its character code. Positions count from 0.
- String
- A sequence of characters, e.g.
'Aisyah'. - Length
- The number of characters in a string, found with
LEN(s). - Substring
- Part of a string extracted with
SUBSTRING(start, end, s). - Concatenation
- Joining strings end to end with
+. - Character code
- The ASCII/Unicode number for a character;
'A'is 65.
Homework 1 min
Task (≤ 15 min): Write, in AQA pseudo-code, a program that inputs a word and outputs it in upper case followed by its length.
Model answer
OUTPUT 'Enter a word' word ← USERINPUT OUTPUT STRING_TO_UPPER(word) OUTPUT LEN(word)
Award marks for: read the input (1), convert to upper case (1), output the length with LEN (1).