String Handlers
String Handlers
2210/23/O/N/22
7 The string operation SUBSTRING(Quote, Start, Number) returns a string from Quote
beginning at position Start that is Number characters long. The first character in Quote is in
position 1.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [5]
2210/23/M/J/22
11 The variables P and Q are used to store data in a program. P stores a string. Q stores a character.
(a) Write pseudocode statements to declare the variables P and Q, store "The world" in P
and store 'W' in Q
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(c) Give the value of Position after the algorithm has been executed with the data in
question 11(a).
...................................................................................................................................................
............................................................................................................................................. [1]
2210/23/M/J/21
8 The function LENGTH(Phrase) calculates the length of a string Phrase
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
Specimen paper 2B
10 A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z) finds a
substring of X starting at position Y and Z characters long. The first character in the string is
position 1.
(a) Show the value of the variable after each pseudocode statement has been executed.
02 Q ← LENGTH(P) ............................................................................................................
03 R ← SUBSTRING(P,10,7) ...........................................................................................
04 S ← LENGTH(R) ............................................................................................................
05 T ← SUBSTRING(R,1,3) .............................................................................................
[5]
(b) Write a pseudocode statement to extract the word Computer from P and store it in the
variable F.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Specimen paper 2A
1 The variables X, Y and Z are used to store data in a program:
X stores a string
Y stores a position in the string (e.g. 2)
Z stores the number of characters in the string.
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
........ [3]
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
......................................................................................................................................
.............
.............................................................................................................................................. [6]