IGCSE · Practice questions · String handling

Count the characters.

Six original Cambridge-style questions on string handling in 0478 pseudocode, with mark points.

Original questions All questions on this page are original work, written in the Cambridge IGCSE style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Number the characters.

01
Recall
[2 marks]

State the purpose of the string operations LENGTH and SUBSTRING.

  • LENGTH returns the number of characters in a string. ✓
  • SUBSTRING returns part of a string: a given number of characters starting at a given position. ✓
02
Trace
[3 marks]

Text ← "Data Science". State what is returned by (a) LENGTH(Text) (b) SUBSTRING(Text, 6, 3) (c) UCASE(SUBSTRING(Text, 1, 4)).

  • (a) 12 (4 + 1 space + 7) ✓
  • (b) "Sci" ✓
  • (c) "DATA" ✓
03
Write
[4 marks]

Write pseudocode that inputs a person's first name and outputs its first letter in upper case and the number of letters in the name.

  • INPUT FirstName ✓
  • Initial ← UCASE(SUBSTRING(FirstName, 1, 1)) ✓
  • OUTPUT Initial ✓
  • OUTPUT LENGTH(FirstName) ✓
04
Write
[4 marks]

Write pseudocode that inputs a sentence and outputs the number of words, assuming words are separated by single spaces.

  • Spaces ← 0 and INPUT Sentence ✓
  • FOR Index ← 1 TO LENGTH(Sentence) ✓
  • IF SUBSTRING(Sentence, Index, 1) = " " THEN Spaces ← Spaces + 1 ✓
  • After the loop: OUTPUT Spaces + 1 ✓
05
Explain
[2 marks]

A login program compares the username typed with the stored username "SMITH". A user types smith and is rejected. Explain why and how to fix it.

  • String comparison is case sensitive: "smith" is not equal to "SMITH". ✓
  • Convert the input with UCASE (or both strings to the same case) before comparing. ✓
06
Analysis
[2 marks]

A student wants characters 3 to 6 of Word and writes SUBSTRING(Word, 3, 6). Explain the error and correct it.

  • The third parameter is the number of characters, so this returns 6 characters (positions 3 to 8). ✓
  • Correct: SUBSTRING(Word, 3, 4). ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.