Welcome back.
In this video, I want to show you another way of manipulating strings.
And we have seen concatenation as well as interpolation.
And there is another one called string formatting.
And string formatting is pretty straightforward to a degree, but it's still just a different way of
using interpolation.
You could say interpolation is just a cooler way, but still, in some code examples you might see string
formatting instead.
And I don't want you to be lost about what is going on in that case.
So I'm going to show you how this is going to look like.
Therefore, I have three variables here num price and name.
So int double and string.
And now I want to say the number is.
And then we've seen how interpolation would have worked.
So we would have had num here and a dollar sign like this.
And we've seen how concatenation would work.
So the number is and then we would have used plus num like so.
So just to summarize this here is called interpolation.
And this is string concatenation.
And now let's look at string formatting.
And therefore I'm going to use Console.WriteLine.
And again just a normal string the number is.
And then I'm using curly brackets here and an index.
So a zero then a comma.
And then the variable that I want to use okay.
So this basically says at position zero.
After this comma there will be a variable.
Please insert it here inside of the string.
So let's add a console.readkey here to keep the software alive to even see what's going on.
And we see in all three cases we get number is three.
So why does that matter?
Well the thing is it's just a different way of doing it.
So this would have been before interpolation was introduced.
This would have been the cleanest way, so to speak.
But you will see examples where it is still like this.
So why do I have three variables here.
Well I wanted to demonstrate how that works for multiple variables.
So let's say and the price is and here I have another curly brackets.
But this time the number is one.
So here I have another comma.
And here I'm using price.
So here I'm now saying at position zero basically the first entry.
Because in coding you start counting at zero.
You don't start counting at one.
There's this meme about coders where there there's this couple and they're saying, hey, meet me at
the first table and the guy sits at table number zero, and the girl sits at table number one.
And they never meet because she doesn't understand programming.
So basically we have this.
The number is zero.
And then the price is one.
And this one will be the second entry.
So this one here will be the price.
Now let's run this again.
And we see the number is ten and the price is 1995.
So now I would like you to try to modify this statement here to also include the name is Frank.
So please pause the video and try it yourself okay I hope you tried it.
So here and the name is and again curly brackets.
This time we're using two.
And then we add comma name okay.
So let me scroll out so we can see the entire line.
So the entire line now says the number is zero and the price is one and the name is two.
So this will be the first entry.
This will be the second entry and this will be the third entry.
So here you don't have to add the variable name or anything like that.
So it is not interpolation.
It is string formatting.
All right.
So let's run this and see how this works.
And we see the number is ten.
And the price is 1995.
And the name is Frank perfect.
So that is a third way of manipulating your strings.
So now you've become a string manipulator professional or a professional string manipulator.
So I hope you enjoyed this video and see you in the next one.