<jupyter_start><jupyter_text>The Basics of StringsWatch the full [C 101 video](https://www.youtube.com/watch?v=JSpC7Cz64h0&list=PLdo4fOcmZ0oVxKLQCHpiUWun7vlJJvUiN&index=3) for this module. What is a String?A string is a sequence of characters. A handy metaphor is a friendship bracelet, where you string together letters to make a name.  Strings and String Literals`firstFriend` and `secondFriend` are variables of strings. The line within `Console.WriteLine` is also a string. It's a **string literal**. A string literal is text what represents a constant string.> Try that out with the following code. Press play and see what comes out.>> Next, try changing the variables to see different names.<jupyter_code>string firstFriend = "Maria";
string secondFriend = "Sophia";
Console.WriteLine($"My friends are {firstFriend} and {secondFriend}");<jupyter_output>My friends are Maria and Sophia<jupyter_text>String PropertiesAs you explore more with strings, you'll find that strings are more than a collection of letters. You can find the length of a string using `Length`. `Length` is a **property** of a string and it returns the number of characters in that string.> Try that out by seeing how long the names of the friends are:<jupyter_code>Console.WriteLine($"The name {firstFriend} has {firstFriend.Length} letters.");
Console.WriteLine($"The name {secondFriend} has {secondFriend.Length} letters.");<jupyter_output>The name Maria has 5 letters.
The name Sophia has 6 letters.<jupyter_text>String Methods Leading and Trailing SpacesSuppose your strings have leading or trailing spaces (also called **white space**) that you don't want to display. You want to trim the spaces from the strings. The `Trim` method and related methods `TrimStart` and `TrimEnd` do that work. You can just use those methods to remove leading and trailing spaces.> Play around with trimming in the following code. The brackets are there to help you see all the white space.**Editing Note: Should this be all one thing? Or multiple breakups of code and markdown?*<jupyter_code>string greeting = "      Hello World!       ";
Console.WriteLine($"[{greeting}]");

string trimmedGreeting = greeting.TrimStart();
Console.WriteLine($"[{trimmedGreeting}]");

trimmedGreeting = greeting.TrimEnd();
Console.WriteLine($"[{trimmedGreeting}]");

trimmedGreeting = greeting.Trim();
Console.WriteLine($"[{trimmedGreeting}]");<jupyter_output>[      Hello World!       ]
[Hello World!       ]
[      Hello World!]
[Hello World!]<jupyter_text>ReplaceYou can also replace substrings with other values. For example, in the code below, you can take "Hello World!" and replace "Hello" with "Greetings", to make "Greetings World!"> Try it out. What else could you replace "Hello" with?<jupyter_code>string sayHello = "Hello World!";
Console.WriteLine(sayHello);
sayHello = sayHello.Replace("Hello", "Greetings");
Console.WriteLine(sayHello);<jupyter_output>Hello World!
Greetings World!<jupyter_text>Changing CaseSometimes you need your strings to be all UPPERCASE or all lowercase. `ToUpper` and `ToLower` do just that.> The following example seems a bit mixed up. Can you fix it so "whisper" is all lowercase, and "shout" is all uppercase?<jupyter_code>Console.WriteLine("WhiSPer".ToUpper());
Console.WriteLine("sHoUt".ToLower());<jupyter_output>WHISPER
shout<jupyter_text>PlaygroundNow it's your turn to play around with what you've learned. Try these exercises:> Create three variables of three different people.>> Find the length of the first person, make the second person all caps, and the third person all lowercase.>> How many letters are in "supercalifragilisticexpialidocious"?>> How many characters are taken out when you trim "       friendship bracelet     "? Does trimming take out the center space?>> What do you want to write?<jupyter_code>Console.WriteLine("Playground");
Console.WriteLine("supercalifragilisticexpialidocious");
Console.WriteLine("       friendship bracelet     ");<jupyter_output>Playground
supercalifragilisticexpialidocious
       friendship bracelet
StarcoderdataJupyterStructuredCleanDedup