Practice String in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

A data type that represents a sequence of characters (text), enclosed in quotation marks.

A string is text in code โ€” anything between quotes. Numbers inside quotes are text too: '42' is a string, not a number.

Example 1

easy
Given s = 'Hello World', what is: (a) LENGTH(s), (b) s[0], (c) s[6..10] (substring from index 6 to 10)?

Example 2

medium
What is the result of concatenating 'Score: ' + STRING(95) + '%'?

Example 3

easy
Given name = 'Alice', what does name + ' is ' + STRING(15) + ' years old' produce?

Example 4

medium
Given word = 'PROGRAMMING', what is the result of each operation? (a) LENGTH(word) (b) word[0] + word[LENGTH(word) - 1] (c) SUBSTRING(word, 3, 4)