×

c# · level 1 · unit 3 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Strings come with tricks built in.

A is a trick a value knows how to do. Write the box name, a dot, the method name and brackets. pet.ToUpper() shouts in capitals and pet.ToLower() whispers in small letters.

.Trim() cuts spaces off both ends, handy when someone types an extra space. .Replace("B", "W") swaps every B for a W, like a find-and-swap button.

counts the letters, spaces and symbols. It has no brackets, because it is a fact about the string, not a trick. Each method gives back new text and leaves the box as it was.

using System;

string pet = "Biscuit";
Console.WriteLine(pet.ToUpper());
Console.WriteLine(pet.ToLower());
Console.WriteLine(pet.Replace("B", "W"));
Console.WriteLine(pet.Length);

To keep the new text, put it back in the box: pet = pet.ToUpper();.