Skip to content

Course home

String handling operations in a programming language

String handling operations in a programming language

EasyMedium
1234567891011121314151617181920
Question 5

A system developer is writing a routine to validate airline baggage tags. A baggage tag is formatted as a string tagID (e.g. "BAG-582914-X"), where:

  • The first 3 characters are the category (indices 0 to 2)
  • A hyphen - is at index 3
  • A variable-length integer numeric identifier starts at index 4
  • Another hyphen - precedes a single-character check digit at the end

The developer uses the variables firstHyphen (representing the index of the first hyphen, which is 3) and secondHyphen (representing the index of the second hyphen, which is 10 in the example) to identify the boundary positions.

Which pseudo-code statement correctly extracts the numeric identifier and assigns it to the variable numIdentifier?

A

numIdentifier ← SUBSTRING(firstHyphen, secondHyphen, tagID)

B

numIdentifier ← SUBSTRING(firstHyphen + 1, secondHyphen - firstHyphen, tagID)

C

numIdentifier ← SUBSTRING(firstHyphen + 1, secondHyphen - firstHyphen - 1, tagID)

D

numIdentifier ← SUBSTRING(secondHyphen - firstHyphen - 1, firstHyphen + 1, tagID)

Markscheme

String handling operations in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /String handling operations in a programming language

89 exam-style questions on AQA GCSE Computer Science String handling operations in a programming language. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank