String Operations in AQA
Strings can be manipulated using built-in functions. AQA specifies the following string operations:
| Function | Description | Example | Result |
| LEN(s) | Length of string s | LEN("Hello") | 5 |
| SUBSTRING(s, start, len) | Extract part of string | SUBSTRING("Hello",0,3) | "Hel" |
| UPPER(s) | Convert to uppercase | UPPER("hello") | "HELLO" |
| LOWER(s) | Convert to lowercase | LOWER("HELLO") | "hello" |
| + | Concatenation (join strings) | "Hello" + " " + "World" | "Hello World" |
LEN — String Length
word ← "Computer"
OUTPUT LEN(word) // 8
// Useful for checking password length:
password ← INPUT()
IF LEN(password) < 8 THEN
OUTPUT "Too short"
ENDIF
SUBSTRING — Extract Part of a String
SUBSTRING(s, start, length) — returns length characters starting from position start (zero-indexed).
text ← "Hello World"
OUTPUT SUBSTRING(text, 0, 5) // "Hello"
OUTPUT SUBSTRING(text, 6, 5) // "World"
OUTPUT SUBSTRING(text, 0, 1) // "H" (first character)
// Last character:
OUTPUT SUBSTRING(text, LEN(text)-1, 1) // "d"
UPPER and LOWER
Used to standardise string comparison — so "YES", "Yes" and "yes" all match:
answer ← INPUT("Continue? ")
IF UPPER(answer) == "YES" THEN
OUTPUT "Continuing..."
ENDIF
Concatenation with +
firstName ← "Alice"
lastName ← "Smith"
fullName ← firstName + " " + lastName
OUTPUT fullName // "Alice Smith"
// Mix number and string — must cast number first:
age ← 16
OUTPUT "I am " + str(age) + " years old"
String Indexing (Characters)
Individual characters can be accessed using SUBSTRING with length 1. Strings are zero-indexed like arrays.
s ← "GCSE"
OUTPUT SUBSTRING(s, 0, 1) // "G"
OUTPUT SUBSTRING(s, 3, 1) // "E"
Exam tip: SUBSTRING is zero-indexed in AQA — position 0 is the first character. The second parameter is the starting position; the third is the length (not end position). Many students confuse end position with length.
⚠️ Common Mistakes
- SUBSTRING("Hello", 1, 3) = "ell" not "Hel" — position 1 starts at 'e', not 'H'
- Confusing the third parameter as an end index — it's the LENGTH
- Forgetting to cast numbers to strings before concatenation
- UPPER/LOWER returns a new string — it doesn't modify the original