Studyfin Studyfin ✨ Sign up free

Strings & string manipulation

Grade 7 · Coding · Free lesson

Hi there! I am Studyfin, your coding buddy. Today, we will explore strings, which are how computers handle text!

In coding, a string is just a chain of characters. It can hold letters, numbers, spaces, and symbols inside quotation marks. We use strings to show messages to users.

ribbon

We can glue two strings together to make one longer string. This is called concatenation. For example, joining 'ice' and 'cream' gives us 'icecream'. We use a plus sign to do this in our code.

"ice" + "cream" "icecream"

We can also find the length of a string, which means counting its characters. Each letter, number, space, and symbol counts as one. For example, the string 'hi!' has a length of three.

C 1 a 2 t 3 Total Length = 3

In real-world programs, we often need to design software that processes strings using loops. Imagine we want to check list items. We can use nested loops to look at each word, and then look at each character inside that word.

✏️ Worked example

Let's design a program to count how many times the letter 'e' appears in a list of words. We will use a software design process to solve this step-by-step.

  1. Identify the subproblems: First, we need to look at each word in our list. Second, we need to inspect each character of that word to check if it is an 'e'.
  2. Design the nested loops: The outer loop will go through each word in the list. The inner loop will go through each character of the current word.
  3. Write the condition: Inside the inner loop, we write an 'if' statement to check if the character matches 'e'. If it does, we add one to our counter.
  4. Test with a list: Let's test our design with the list ['bee', 'cat']. The outer loop picks 'bee'. The inner loop checks 'b', 'e', and 'e', counting two 'e's. Next, the outer loop picks 'cat'. The inner loop checks 'c', 'a', and 't', counting zero. The final count is two!
marine
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons