>> In our last tutorial, be covered Hello World.
Now, we're going to talk a little bit more about Strings.
So how do you think of Strings?
>> We said Strings a lot.
You hear that in programming elegant String this,
attach this String is other String.
I think about it like friendship bracelets.
Remember when you'd go you make your friendship bracelet,
and you string these different letters together.
You take characters with your name,
you put them onto the string,
and you get a friendship bracelet that
says Kendra,that says Scott.
>> Yeah.
>> That's what I think is Strings.
>> The little ties that the end can be the quotation marks.
>> I didn't think about that. Just a little note
to the end of the quotation mark.
That's a really great way to think about Strings.
So we're going to talk about Strings right now.
So we'll switch back over to where we left off in Docs.
When you last saw us,
we were doing step two of seven inside of docs.Microsoft.com.
I'm going to hit "Next." We're going to work with Strings.
Before we had said there was a variable called a friend,
and we said hello or friend.
But here we have something more interesting.
We have two friends now, first and second.
So I'll hit "Copy",
and I'm going to paste over the top with again Control V and
I'll say Scott and Kendra, and I'll hit "Run" again.
>> So here, we actually are able to use two interpolated Strings.
So first friend is the first variable that we declare as Scott,
and second friend is
the second variable that we declare as Kendra.
You can see in our output on
the bottom that my friends are Scott and Kendra.
>> These are Strings with names. They're variables.
First friend is the name String,
and second friend is a String with a name.
Then this String inside of console.writeline is also a String.
It just doesn't have a name.
It's literally a String,
and sometimes you'll hear people call that a String literal.
>> Oh, yeah. Then we have the little dollar sign in there.
That dollar sign is cool.
It makes it magic.
>> It does.
>> You see that word interpolating.
I don't know what interpolated really means,
but I do know that if I remove the dollar sign,
it breaks my code.
If I go and say "Run", look what it does.
It literally shows the String literal.
But if I add back that dollar sign,
suddenly, that String means a lot more.
>> Definitely. So Strings can also
have a lot of different properties on them.
So in our next example,
we actually access the length property,
and that's going to tell us
how many characters are contained in this String.
>> So I'm going to copy that example,
and I'll come over here and I can add onto that.
So I'm going to keep the first code that I copied from before.
I'm going to add this code at the bottom and you'll
see as Kendra just pointed out,
first friend is our String,
and.length is a property of our String.
So let's hit "Run" and see what that says. There we go.
The name Scott has five letters,
and Kendra has six letters.
It's also worth pointing out that if I maybe mistyped that,
if I typed in some that's not like it,
not only am I going to get a squiggly,
like when you get a spelling error in word.
But when I hit "Run" it's going to tell you,
"Oh, I don't know what Lex is.".
>> Lex.
>> Lex. We have no Lex here.
>> That's not a property on a String.
>> No, sorry it's length,
and then we hit "Run" and then we come back, and it works.
>> Cool.
>> Cool. Let's move to the next step and learn more about Strings.
So sometimes Strings have leading or trailing spaces.
That's an interesting one.
Do you want to delete all of
this code and replace it with this code?
>> Yeah. Let's start over with a clean fleet.
>> So I'm going to go and select all of that text there,
and I'll hit "Delete or Backspace" and I'll paste in this text.
Look at this String up here.
What's going on here?
>> So yeah, it looks like it has
an extra tab or a bunch
of extra spaces before and after Hello World.
>> Yeah, and I call that a whitespace.
>> Yeah. I don't want that whitespace.
If I go and say run, oh this is interesting.
Look what happened here. They put a little square bracket.
I could put even stars if I want to.
I could say star, star,
star or just some character.
They're doing that to show
us that we'd have visualized the whitespace.
>> Yes. So where it actually started and ended.
>> So there's nothing special about the bracket in this example.
It's just them saying,
here's our character that you'll recognize,
and then your String that you want,
and then another character that you recognized.
So we can visualize that space.
Then here on the next line, on line 4,
we're going to say, "Hey,
let's take the String called greeting and let's trim it.
Let's just chop off."
So what are we trimming?
Are we trimming a number of things?
No, we're trimming the whitespace.
So we have trim start,
trim end, and then just trim.
>> So just trim, trims all of it.
>> Right. So this is interesting.
It shows us that that whitespace,
or spaces and you said tabs, are a thing.
That they really matter. Whitespace and spaces matters.
So sometimes you need
to think about that when you're dealing with Strings.
>> Definitely. So this can help you better
format the String before you output it.
Now strings have length we talked about before.
They have methods. In this case,
we're actually calling a method.
See how we said trim start and then we had parenthesis.
The parentheses indicate that it's another line.
>> If I get rid of those parentheses,
and I try to run it, it's going to say I don't know what that is.
That's not a thing.
If put that back and I hit "Run." Now, it works.
Yeah.
If I said.length, that's not a method, that's a property.
You have to keep track of those things when we're doing this work.
Here's another useful method of a String.
Replace. Let's try that.
So we'll paste that in.
>> Yeah.
>> Hello World.
>> So here it looks like we have a String that says Hello World,
and we want to write it out before we do anything with it.
>> So we're writing it right there.
>> So we have our console.writeline,
and then the next place next place.
>> I'll cheat and I'll do it right now.
>> Oh, yeah.
>> Okay.
>> So that's what it looked like before we do anything with it.
>> Okay.
>> Now let's call this, sayHello.Replace.
So we're taking the say Hello String,
and we're replacing part of it,
let's say the Hello with it should be Greetings.
>> Okay.
>> So let's go ahead and write that again.
>> All right. So we said Hello World,
which was inside of say Hello.
We output it, that's that first line.
Now, this is really interesting here.
Look, it said sayHello equals sayHello again.Replace.
So when we replace that String,
I imagine another String shooting out of the back of this one,
and now we've changed sayHello.
So this variable, sayHello,
has different stuff in it now.
>> Yeah, and the calling replace on it actually searched for where
Hello exist in the original String and replaced it with Greeting.
>> Exactly. If I change that,
I can say Hello World becomes Kendra World.
>> I like the sound of that.
>> Yeah. So we can manipulate these Strings.
Again, the result of that replace comes out.
We can see that again if we do and try these variables,
if you want to make something maybe all caps, all lowercase.
Let's go and take these lines here,
and at the end of Kendra World,
we'll go and say console.writeline again.
We're passing in sayHello,ToUpper and sayHello, ToLower.
So I think I know what's going to happen when we hit "Run".
>> So the first one is shouting because it changed it to all caps.
>> That'll be your album cover title there,
a low key lowercase Kendra World.
So this is interesting because we didn't actually change sayHello,
we didn't assign it to a variable,
we didn't say, sayHello equals sayHello,ToUpper,
we just changed it in place.
>> Right. So if you actually
did a console.writeline again for just sayHello,
and print that out, you'll notice that
sayHello wasn't permanently changed.
It still has capitalization that it had in the beginning.
>> That's a great point. So here we can
go and see the state of our variable.
Sometimes when you're just getting started,
you're going to find yourself console.write
running a lot just to know
what's really going on with your variables,
which is cool. Wow, that's a lot.
>> Yeah.
>> So we've learned a little bit about Strings.
Let's take a breather, and then we'll go to
the next video and we'll get deeper into Strings and C#.