AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Programming
String-handling operations
- 3 things to know
- Paper 1
Overview
Recall questions on length, position, substring and concatenation, on where positions are counted from, and on converting between characters and their character codes.
What you need to know
Answer each one before you reveal it.
What does a string to float conversion do, and when do you need it rather than string to integer?
What does a date/time to string conversion do?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What does the length operation do? What is the length of 'Computing' and of the empty string?
Model answer
It returns the number of characters in a string. 'Computing' has length 9 and the empty string has length 0. Spaces and punctuation are characters and count towards the length, so 'A B' has length 3.
- 2
What does the position operation do, and what does it return when the item is not there?
Model answer
It searches a string for a character or a substring and returns the index at which the first occurrence starts. If the item does not occur, it returns an agreed value that cannot be a valid index, typically -1 or 0 depending on the language. Only the first occurrence is reported, so finding later ones means searching again from beyond that point.
- 3
Where does the position of a character get counted from, and why must you check this?
Model answer
Some languages number the characters of a string from 0 and others from 1, so in 'Computing' the letter 'm' is at position 2 counting from zero but at position 3 counting from one. Getting the base wrong produces answers that are consistently out by one, which is one of the commonest string-handling bugs.
- 4
What does the substring operation do? Extract the first three characters of 'Computing'.
Model answer
It returns a section of a string, given a starting position and either a length or an end position. Taking three characters from the start of 'Computing' gives 'Com'. The original string is unchanged; the operation returns a new string.
- 5
What does concatenation do, and what does 'Comp' joined to 'uting' give?
Model answer
It joins two strings end to end to produce a single longer string, so 'Comp' and 'uting' concatenate to 'Computing'. Nothing is inserted between them, so joining a first name to a surname needs a space concatenated in as well. In most languages the operator is +, though some use & or a join function.
- 6
What does the character to character code operation do? What is the code for 'A'?
Model answer
It returns the numeric code that represents a given character in the coding scheme being used, so in ASCII the character 'A' gives 65. It is often written ord(c) or ASC(c).
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of Programming, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.