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.
| Function | What it does | Example | Result |
|---|---|---|---|
LENGTH(s) | Returns the number of characters in string s | LENGTH("Hello") | 5 |
LCASE(s) | Returns string converted to all lowercase | LCASE("HELLO") | "hello" |
UCASE(s) | Returns string converted to all uppercase | UCASE("hello") | "HELLO" |
SUBSTRING(s, start, length) | Extracts a portion of string s starting at position start for length characters | SUBSTRING("Hello", 2, 3) | "ell" |
LEFT(s, n) | Returns the first n characters from the left of s | LEFT("Hello", 3) | "Hel" |
RIGHT(s, n) | Returns the last n characters from the right of s | RIGHT("Hello", 3) | "llo" |
INT(x) | Converts a REAL to INTEGER (truncates) | INT(3.7) | 3 |
STRING(x) | Converts a number to a STRING | STRING(42) | "42" |
NUM_TO_STR(x) (alternative) | Converts number to string | NUM_TO_STR(42) | "42" |
The & operator joins two strings together.
first ← "Alice" last ← "Smith" full ← first & " " & last OUTPUT full // Outputs: Alice Smith
name ← "Alice"
IF LEFT(name, 1) = "A" THEN
OUTPUT "Name starts with A"
ENDIF
email ← "alice@school.ac.uk" // Extract the part before @ atPos ← 6 // position of @ username ← LEFT(email, atPos - 1) OUTPUT username // Outputs: alice
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
INPUT answer
IF LCASE(answer) = "yes" THEN
OUTPUT "You agreed"
ENDIF
// Accepts "YES", "Yes", "yes", "YeS" etc.
4 questions · 10 marks
| Term | Definition |
|---|
10 minutes · mixed marks