String Manipulation Flashcards

Card 1 of 7

All 7 cards in this deck

In OCR Exam Reference Language, 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

How do you find the number of characters in a string?

e.g. word = "computer"

word.length — this gives 8.

What does .substring(x , i) return?

e.g. subject = "computer", subject.substring(3,5)

i characters starting at index x, where indexes start at 0 — returns "puter".

What do .left(i) and .right(i) return?

e.g. word = "computer", then word.left(3) and word.right(2)

.left(i) gives the first i characters and .right(i) the last i characters — "com" and "er".

What do .upper and .lower do?

e.g. "Cat".upper

.upper converts every letter of the string to uppercase and .lower converts every letter to lowercase — gives "CAT".

What do ASC() and CHR() do?

e.g. given that the character code for "A" is 65: ASC("A") and CHR(66)

ASC() returns the character code of a character and CHR() returns the character for a code — 65 and "B".

True or false? Spaces and punctuation are counted by .length when finding the number of characters in a string.

True. .length counts every character in the string, including spaces and punctuation.