String Operations (SQA National 5 Computing Science): Revision Note
Exam code: X816 75
String operations
What are string operations?
String operations are programming techniques used to modify, analyse, or extract information from a string
Examples of string operations include:
Case conversion (modify)
Length (analyse)
Substring (extract)
Concatenation (modify)
Case conversion
The ability to change a string from one case to another, for example, lower case to upper case
Operation | SQA pseudocode | Python equivalent | Output |
|---|---|---|---|
Uppercase |
|
|
|
Lowercase |
|
|
|
Length
The ability to count the number of characters in a string, for example, checking whether a password meets the minimum requirement of 8 characters
SQA pseudocode | Python equivalent | Output |
|---|---|---|
|
|
|
|
|
|
Substring
The ability to extract a sequence of characters from a larger string, for example, for validation or combining with other strings
In SQA pseudocode, a substring starts at position 1 (not 0 as in Python)
SQA pseudocode | Python equivalent | Output |
|---|---|---|
|
|
|
|
|
|
Concatenation
The ability to join two or more strings together to form a single string
In SQA pseudocode, concatenation uses the ampersand (
&) operator to join strings togetherIn Python, the plus (
+) operator is used
Operation | SQA pseudocode | Python equivalent | Output |
|---|---|---|---|
Concatenating two strings |
|
|
|
Concatenating two strings with a space |
|
|
|
Concatenating text and variables |
|
|
|
Worked Example
A program is designed to output a welcome message using the user’s name.
Complete the missing line of code so that the output will be Welcome, Jordan
DECLARE name INITIALLY "Jordan"
SEND __________________________ TO DISPLAY
[1]
Answer
Correct use of concatenation to join text and variable [1 mark]
SEND "Welcome, " & name TO DISPLAY
Unlock more, it's free!
Did this page help you?