Studyfin Studyfin ✨ Sign up free

Strings & string manipulation

Grade 8 · Coding · Free lesson

Hey there! Ready to explore the world of coding? Today, we will learn how computers handle text using strings!

In coding, any text inside quotation marks is called a string. It can be a single letter, a whole word, or even a full sentence with spaces and punctuation.

ribbon

We can glue strings together using a process called concatenation. Think of it like snapping toy train cars together to build a longer train.

"Co" + "de" "Code"

Every character in a string has an address called an index, starting at 0. We can find the length of a string by counting all its characters, including spaces!

F I N D Index 0 Index 1 Index 2 Index 3 Total Length = 4 characters
✏️ Worked example

Let's build a smart greeting! We want to take a user's name, like "Sam", and turn it into a friendly shoutout: "** SAM **". How do we design a program to do this step-by-step?

  1. First, we find the input name. Let's use the string variable: name = "Sam".
  2. Next, we use a built-in string method to change all the letters to uppercase. This turns "Sam" into "SAM".
  3. Now, we want to add decorative stars to the left and right. We create a new string variable containing the star pattern: stars = "** ".
  4. Finally, we glue them together using concatenation. We add stars + name + stars to get our final output: "** SAM **".
guitar
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons