📘 Paper 2 · Topic 8: Programming
8.5 String Handling
Cambridge IGCSE Computer Science 0478 · ~14 min read · ⭐ Pro

String Handling Functions

String handling refers to manipulating text (STRING) values. Cambridge IGCSE requires knowledge of several built-in string functions, each of which is tested regularly in exams.

Cambridge String Functions Reference

FunctionWhat it doesExampleResult
LENGTH(s)Returns the number of characters in string sLENGTH("Hello")5
LCASE(s)Returns string converted to all lowercaseLCASE("HELLO")"hello"
UCASE(s)Returns string converted to all uppercaseUCASE("hello")"HELLO"
SUBSTRING(s, start, length)Extracts a portion of string s starting at position start for length charactersSUBSTRING("Hello", 2, 3)"ell"
LEFT(s, n)Returns the first n characters from the left of sLEFT("Hello", 3)"Hel"
RIGHT(s, n)Returns the last n characters from the right of sRIGHT("Hello", 3)"llo"
INT(x)Converts a REAL to INTEGER (truncates)INT(3.7)3
STRING(x)Converts a number to a STRINGSTRING(42)"42"
NUM_TO_STR(x) (alternative)Converts number to stringNUM_TO_STR(42)"42"

Concatenation

The & operator joins two strings together.

first ← "Alice"
last ← "Smith"
full ← first & " " & last
OUTPUT full    // Outputs: Alice Smith

Worked Examples

Example 1: Checking the first character

name ← "Alice"
IF LEFT(name, 1) = "A" THEN
    OUTPUT "Name starts with A"
ENDIF

Example 2: Extracting a username prefix

email ← "alice@school.ac.uk"
// Extract the part before @
atPos ← 6   // position of @
username ← LEFT(email, atPos - 1)
OUTPUT username   // Outputs: alice

Example 3: Using LENGTH in a loop

word ← "Cambridge"
FOR i ← 1 TO LENGTH(word)
    OUTPUT SUBSTRING(word, i, 1)
NEXT i
// Outputs each character on a new line: C, a, m, b, r, i, d, g, e

Example 4: Converting to lowercase for comparison

INPUT answer
IF LCASE(answer) = "yes" THEN
    OUTPUT "You agreed"
ENDIF
// Accepts "YES", "Yes", "yes", "YeS" etc.
Exam tip: SUBSTRING(s, start, length) is the most commonly tested string function. Remember it has 3 parameters: string, start position, and length of substring to extract. Cambridge pseudocode uses 1-based indexing — position 1 is the first character. Be careful: SUBSTRING("Hello", 2, 3) = "ell" (starts at position 2, takes 3 characters).
⚠️ Common Mistakes
  • Using 0-based indexing: position 1 is the FIRST character in Cambridge pseudocode, not 0
  • Confusing the parameters of SUBSTRING: it's (string, start, length) — NOT (string, start, end)
  • Using + to join strings instead of & — in Cambridge pseudocode, use & for concatenation
  • Forgetting that LCASE/UCASE return a new string — the original variable is unchanged
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — String Handling

4 questions · 10 marks

Q1What is the result of each expression? (a) LENGTH("Computer") (b) LEFT("Science", 3) (c) SUBSTRING("Algorithm", 5, 4) [3]
✅ Mark scheme
(a) 8 [1]; (b) "Sci" [1]; (c) SUBSTRING("Algorithm", 5, 4) — positions: A(1)l(2)g(3)o(4)r(5)i(6)t(7)h(8)m(9) — starts at 5 for 4 chars = "rith" [1]
Q2Write pseudocode to input a word and output it in UPPERCASE. [2]
✅ Mark scheme
INPUT word [1]; OUTPUT UCASE(word) [1]
Q3Write pseudocode that inputs a password and checks if it is at least 8 characters long. Output "Valid" or "Too short". [3]
✅ Mark scheme
INPUT password [1]; IF LENGTH(password) >= 8 THEN [1]; OUTPUT "Valid" ELSE OUTPUT "Too short" ENDIF [1]
Q4Explain what LCASE() is useful for and give an example of when you would use it. [2]
✅ Mark scheme
LCASE() converts a string to lowercase, allowing case-insensitive comparisons [1]. Example: when checking a yes/no answer — IF LCASE(answer) = "yes" — this accepts "YES", "Yes" or "yes" [1]
Quiz — String Handling
Q 1 of 7
Score
/ 7
Click to reveal
TermDefinition
🎯

Mini Test — String Handling

10 minutes · mixed marks

← 8.4 File Handling Topic 8: Programming Next: 9.1 Boolean Logic →
🔒
Pro Content
Upgrade to access all lessons.
£7.99/month
or £59/year
Subscribe now →