Length, Position, Substring & Concatenation Flashcards

All 6 cards in this deck

In AQA pseudo-code, how do you join two strings together?

e.g. join firstName and surname with a space between them

With the + operator (concatenation):

fullName ← firstName + ' ' + surname

In AQA pseudo-code, how do you find the number of characters in a string?

e.g. word ← 'computer'

LEN(word), which gives 8.

What does SUBSTRING(start, end, s) return in AQA pseudo-code?

e.g. SUBSTRING(3, 7, 'computer')

The characters of s from position start to position end, with both included and positions counted from 0. Here it returns 'puter'.

True or false? LEN counts spaces and punctuation when finding the number of characters in a string.

True. LEN counts every character, including spaces and punctuation, e.g. LEN('Hi, Sam') is 7.

What does POSITION(s, c) return in AQA pseudo-code?

e.g. POSITION('keyboard', 'b')

The position of the first occurrence of the character c in the string s, counting from 0. Here it returns 3.

In AQA pseudo-code, how do you get a single character from a string?

e.g. the first letter of name

Use SUBSTRING with the same start and end position, counting from 0: SUBSTRING(0, 0, name)