String Manipulation Flashcards
All 8 cards in this deck
In OCR Exam Reference Language, how do you join two strings together?
e.g. join
firstNameandsurnamewith a space between themWith the
+operator (concatenation).fullName = firstName + " " + surnameHow do you find the number of characters in a string?
e.g.
word = "computer"word.length— this gives8.What does
.substring(x , i)return?e.g.
subject = "computer",subject.substring(3,5)icharacters starting at indexx, where indexes start at 0 — returns"puter".What do
.left(i)and.right(i)return?e.g.
word = "computer", thenword.left(3)andword.right(2).left(i)gives the firsticharacters and.right(i)the lasticharacters —"com"and"er".What do
.upperand.lowerdo?e.g.
"Cat".upper.upperconverts every letter of the string to uppercase and.lowerconverts every letter to lowercase — gives"CAT".What do
ASC()andCHR()do?e.g.
ASC("A")andCHR(66)ASC()returns the character code of a character andCHR()returns the character for a code —65and"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"- Take the characters needed:
part = surname.left(3)→"Wat" - Convert the case:
part = part.lower→"wat" - Concatenate:
username = part + id→"wat42"
- Take the characters needed:
True or false? Spaces and punctuation are counted by
.lengthwhen finding the number of characters in a string.True.
.lengthcounts every character in the string, including spaces and punctuation.