Skip to content
VirtusAcademy

String Manipulation

FoundationHigherAQA

Revise String Manipulation for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers for AQA GCSE Computer Science (8525). String manipulation extracts, joins and changes parts of text, such as length, substrings and case.

Free downloads

These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.

Topic overview

String manipulation extracts, combines and examines parts of text. Several operations must be known.

Length gives the number of characters. Substring extracts part of a string, given a starting position and a length. Concatenation joins strings together. Position finds where a character or substring occurs. Conversion changes case, or converts between a string and a number.

The detail that causes most errors is indexing. String positions usually start at 0, not 1, so the first character of "HELLO" is at position 0 and the last is at position 4. Assuming positions start at 1 gives an answer one out every time.

Revision notes

The main operations

LEN(string) gives the number of characters.

SUBSTRING extracts part of a string from a starting position for a given length. Concatenation joins strings, often with +. POSITION finds where a character occurs.

Zero-based indexing

String positions usually start at 0, not 1.

In "HELLO", H is at position 0, E at 1, and O at 4. The length is 5 but the last position is 4. Assuming positions start at 1 produces an off-by-one error every time.

Type conversion

Converting between strings and numbers is often needed.

A number entered by a user arrives as a string and must be converted before arithmetic. Converting the other way allows a number to be joined into a message with concatenation.

Key points

  • LEN gives the number of characters.
  • SUBSTRING extracts part of a string.
  • Concatenation joins strings together.
  • String positions usually start at 0.
  • The last position is the length minus 1.
  • Numbers from input arrive as strings.

Worked examples

Example 1

State the length of the string "COMPUTER" and the position of the first character. [2 marks]

Working

The length is 8, as there are 8 characterscount the characters
The first character C is at position 0, because indexing starts at 0state the starting position

Example 2

Explain why the last character of a string of length 6 is at position 5. [2 marks]

Working

Positions start at 0 rather than 1state the indexing rule
so positions run from 0 to 5, making the last position one less than the lengthexplain the consequence

Example 3

A user enters a number which is stored as a string. Explain what must happen before it is used in a calculation. [2 marks]

Working

The string must be converted to a numeric data type such as an integerstate what is needed
otherwise the + operator would concatenate the values rather than adding themexplain why

Common mistakes

  • Assuming positions start at 1.

    They usually start at 0, making the last position length minus 1.

  • Forgetting to convert input before arithmetic.

    Input arrives as a string and would be concatenated, not added.

  • Confusing length with last position.

    Length is one more than the last position.

  • Miscounting substring length.

    Substring takes a start position and a number of characters.

Exam tips

  • Remember indexing starts at 0.
  • The last position is the length minus 1.
  • Convert input before doing arithmetic.
  • Count characters carefully when finding a length.

Key terms

String
A sequence of characters.
Substring
Part of a string extracted from it.
Concatenation
Joining strings together.
Index
The position of a character, starting at 0.

Written and reviewed against the current AQA specification. Spotted an error? Let us know.