24.1 What are Strings?
- A string is a sequence of characters (letters, digits, symbols) treated as text.
- String literals are written inside double quotes, e.g.
"Hello". - Declare a string variable with
DECLARE Name : STRING. - Assign a value using the
<-operator. - The first character is at position 1 (1-indexed in CIE pseudocode).
DECLARE Name : STRING
Name <- "Alice"
OUTPUT Name
OUTPUT "Hello, " + NameKey idea: The empty string "" has zero characters — LENGTH("") returns 0. It is different from " " (a single space) which has length 1.
What are Strings?
24.2 String Functions
LENGTH(S)returns the number of characters inS.UCASE(S)returnsSwith all letters in uppercase.LCASE(S)returnsSwith all letters in lowercase.- These functions return a value — assign to a variable or use in OUTPUT.
DECLARE Word : STRING
Word <- "Hello"
OUTPUT LENGTH(Word) // 5
OUTPUT UCASE(Word) // HELLO
OUTPUT LCASE(Word) // helloExam tip: LENGTH("Hi there") returns 8 — spaces count as characters. Always count carefully when a string contains spaces.
String Functions
24.3 String Concatenation
- The
+operator joins (concatenates) two strings into one. - Order matters:
A + Bis not the same asB + A. - Concatenation does not add a space automatically.
- You can mix string variables and string literals freely.
DECLARE FirstName, LastName, FullName : STRING
FirstName <- "John"
LastName <- "Smith"
FullName <- FirstName + " " + LastName
OUTPUT FullName // John SmithCommon mistake: FullName <- FirstName + LastName produces "JohnSmith" (no space). You must insert a literal " " between the two names.
String Concatenation
24.4 Substrings
SUBSTRING(S, Start, Length)extractsLengthcharacters fromSstarting at positionStart.Startis 1-indexed — position 1 is the first character.- The result is a new string; the original variable is unchanged.
- Use
SUBSTRINGto extract initials, file extensions, or area codes.
DECLARE S, Sub : STRING
S <- "COMPUTER"
Sub <- SUBSTRING(S, 2, 4) // "OMPU"
OUTPUT Sub
OUTPUT SUBSTRING(S, 1, 3) // "COM"Key idea: Start is inclusive — the character at position Start is included in the result. For "COMPUTER", position 1 is C, position 4 is P.
Substrings
24.5 Comparing Strings
=returnsTRUEif two strings are identical.<>returnsTRUEif two strings are different.- Comparison is case-sensitive:
"abc"is not equal to"ABC". - For case-insensitive comparison, apply
UCASE(orLCASE) to both sides.
DECLARE Password : STRING
INPUT Password
IF UCASE(Password) = "SECRET" THEN
OUTPUT "Access granted"
ELSE
OUTPUT "Access denied"
ENDIFExam tip: UCASE() leaves digits and symbols unchanged, so wrapping both sides of a comparison is always safe — it only normalises the case of letters.
Comparing Strings
24.6 Practical Examples
- Username validation — check
LENGTH(Username) >= 6. - Initials extraction —
UCASE(SUBSTRING(Name, 1, 1)). - Password check — compare against a stored value with
UCASE().
Username validation
DECLARE Username : STRING
INPUT Username
IF LENGTH(Username) >= 6 THEN
OUTPUT "Valid username"
ELSE
OUTPUT "Too short"
ENDIFInitials extraction
DECLARE First, Last, Initials : STRING
INPUT First
INPUT Last
Initials <- UCASE(SUBSTRING(First, 1, 1))
Initials <- Initials + UCASE(SUBSTRING(Last, 1, 1))
OUTPUT InitialsExam tip: Initials are a classic exam question — combine SUBSTRING, UCASE and + to extract and join the first letter of each name.
Practical Examples
24.7 Key Points Summary
Recap of every string concept covered in this topic — memorise these and you will be ready for any IGCSE / O Level strings question.
Strings are sequences of characters in double quotes.
DECLARE : STRING creates a string variable.
<- assigns a value to a string variable.
LENGTH(S) returns the character count (includes spaces).
UCASE(S) / LCASE(S) change the case of letters.
+ concatenates strings (no auto-space).
SUBSTRING(S, Start, Length) extracts characters (1-indexed).
= and <> compare strings (case-sensitive).
Use UCASE() / LCASE() for case-insensitive comparison.
Combine functions: LENGTH(UCASE(S)) or SUBSTRING(S, 1, 1) + ....
Exam tip: When a question asks you to "validate" or "check" a string, reach for LENGTH first; when it asks to "extract", reach for SUBSTRING; when it asks to "combine", reach for +.