String Manipulation Flashcards

All 8 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. ASC("A") and CHR(66)

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

What are the steps to build a username from the first 3 letters of a surname plus an ID?

e.g. surname "Watson", id "42"

  1. Take the characters needed: part = surname.left(3) → "Wat"
  2. Convert the case: part = part.lower → "wat"
  3. Concatenate: username = part + id → "wat42"

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.