Strings

IGCSE / O Level Strings

Learn how to declare, manipulate and compare text in CIE pseudocode using built-in functions like LENGTH, UCASE, LCASE, SUBSTRING and the + concatenation operator.

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, " + Name

Key idea: The empty string "" has zero characters — LENGTH("") returns 0. It is different from " " (a single space) which has length 1.

24.2 String Functions

  • LENGTH(S) returns the number of characters in S.
  • UCASE(S) returns S with all letters in uppercase.
  • LCASE(S) returns S with 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)      // hello

Exam tip: LENGTH("Hi there") returns 8 — spaces count as characters. Always count carefully when a string contains spaces.

24.3 String Concatenation

  • The + operator joins (concatenates) two strings into one.
  • Order matters: A + B is not the same as B + 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 Smith

Common mistake: FullName <- FirstName + LastName produces "JohnSmith" (no space). You must insert a literal " " between the two names.

24.4 Substrings

  • SUBSTRING(S, Start, Length) extracts Length characters from S starting at position Start.
  • Start is 1-indexed — position 1 is the first character.
  • The result is a new string; the original variable is unchanged.
  • Use SUBSTRING to 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.

24.5 Comparing Strings

  • = returns TRUE if two strings are identical.
  • <> returns TRUE if two strings are different.
  • Comparison is case-sensitive: "abc" is not equal to "ABC".
  • For case-insensitive comparison, apply UCASE (or LCASE) to both sides.
DECLARE Password : STRING
INPUT Password
IF UCASE(Password) = "SECRET" THEN
  OUTPUT "Access granted"
ELSE
  OUTPUT "Access denied"
ENDIF

Exam tip: UCASE() leaves digits and symbols unchanged, so wrapping both sides of a comparison is always safe — it only normalises the case of letters.

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"
ENDIF

Initials extraction

DECLARE First, Last, Initials : STRING
INPUT First
INPUT Last
Initials <- UCASE(SUBSTRING(First, 1, 1))
Initials <- Initials + UCASE(SUBSTRING(Last, 1, 1))
OUTPUT Initials

Exam tip: Initials are a classic exam question — combine SUBSTRING, UCASE and + to extract and join the first letter of each name.

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 +.

Question Bank

Answer all questions, then press Submit Quiz to see your score.

0/12 answered

Question 1Multiple Choice

What is the output of OUTPUT LENGTH("Hello") ?

Question 2True / False

UCASE() affects only letters; digits and symbols are returned unchanged.

Question 3Multiple Choice

OUTPUT SUBSTRING("PROGRAM", 3, 4)

Question 4True / False

The + operator always means numeric addition in CIE pseudocode.

Question 5Multiple Choice

Given A <- "Data" and B <- "Base", what is the value of A + B ?

Question 6Multiple Choice

What is the correct way to do a case-insensitive comparison of two strings A and B?

Question 7True / False

The first character of a CIE pseudocode string is at position 0.

Question 8Multiple Choice

What does LCASE("HELLO") return?

Question 9Multiple Choice

How do you extract the first 3 characters of the string "Computer"?

Question 10True / False

"Apple" = "apple" returns TRUE in CIE pseudocode.

Question 11Multiple Choice

DECLARE Empty : STRING
Empty <- ""
OUTPUT Empty + "X"

Question 12True / False

LENGTH() counts spaces inside a string.

Answer all 12 questions to enable submission.