Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Welcome back.
And this video I would like to teach you about stream manipulation, and that's going to be quite important
because you are going to need it throughout your coding experience and career.
So this is an extra lecture where we are going to talk about different ways of printing data on the
screen.
And we're going to look at composite strings, string formatting, string interpolation and verbatim
strings.
So, of course, you can stick to one way if you prefer one, but if you like all of them, then it's
fine.
But try to stick to one style throughout your project.
So let's first of all define a few variables.
So inside of my main method, I'm going to create two new variables.
One is going to be H and then the name will be Alphonsus.
So we have an integer, an age and the string name.
Now let's first of all use string concatenation and I have covered this keyword before.
Let's look at this real quick.
So here we are using string concatenation where we say hello, my name is, and then the plus sign the
variable plus and then another string, so to speak, plus another variable plus another string, so
to speak.
OK, so we have an in our an integer example where we basically said what kind of variables we are adding
together in order to get a sum.
So this is string concatenation.
So let's run this and look at it and we will see it says String Concatenation.
Hello, my name is Alfonso.
I am 31 years old.
So this works flawlessly with integers as well as with strings here.
So this is a string and this is an integer and we are using it in string concatenation and there's no
problem with it in Arkansas.
Right.
Line statement here.
All right.
Now let's look at the string formatting concept, OK?
This is going to be a little more advanced, so let's look at it.
So string formatting uses the index.
OK, so here I have a statement that says that this is string formatting.
Then we also use hello, my name is.
But this time we don't end to string and use concatenation, but instead we're using curly brackets,
then index zero for the first entry and index one for the second entry.
So what we're saying is whatever is going to come after this comma here after my string add position
zero.
So the first entry will be positioned here and whatever is positioned, it's the index one, which is
the second entry will be positioned here.
So now we are going to replace zero this year with whatever the name value is and one with whatever
the H value is.
Let's run this and see if this is going to work as well.
And we see.
Hello, my name is Alfonso.
I'm thirty one years old.
So now for you is a little challenge.
Create another variable up here, define one with a value assigned to it and use it inside of the string
formatting real quick so you can use any value there.
OK, so I'm going to create another string, I'm going to call this one job and it will be developer.
Like, so I'm so-and-so years old, I'm a developer or not developer, but in curly brackets, too.
So now it's going to be index to and I'm going to add the developer variable here.
And actually it was called Java.
So let me scroll out a little bit so we can see the entire line.
So here it says, hello, my name is zero.
I am one year old and I am two.
So these numbers are, of course, not the actual values, but they're going to be replaced with whatever
we have here.
So I hope you try this and you were successful at trying it.
So here I'm adding to another entry and that will say job.
So let's see.
Hello, my name is Alfonz.
I'm 31 years old.
I'm a developer.
All right.
So that worked great.
Now let's look at string interpellation, OK?
And I'm going to use it here.
So this is the third concept of how you can manipulate your string, and that is called string interpolation.
So string interpolation uses the dollar sign at the start, which will allow us to write our variables
like this so directly use the variable name instead of having to use indexes.
So here I'm adding the dollar at the beginning of the string.
Hello, my name is then the name.
I am eight years old now.
You can leave name and age to appear at the end, but it's really not necessary at this point anymore.
You can leave it out and you can run the code and you will see that it works the same way.
So hello, my name is Alfonso and I'm thirty one years old.
OK, so this is the more descriptive way why you don't have to use these indexes and you're never sure
which variable was where.
Well, that's not really the case, but still it's a little more complex.
I believe that this is a rather good way of doing it.
Well, you don't have to use Plus's all the time.
And then we have number four, which are verbatim strings.
OK, so let's look at those so verbatim strings.
We need to use that and tell the compiler to take the string literally and ignore any spaces and escape
characters like the back end.
So let me show you what that means.
So therefore, I need to have a slightly bigger statement here.
Let me add that in there.
Like so so now I have a super long string here and it has a lot of thought and maybe some text.
So what this will do it it will on one hand ignore any spaces and escape characters like backslash and
but at the same time, you see it takes the string literally.
So wherever we have an empty space, let me add a couple in here, it's going to literally translate
them.
So here you see I have two more spaces or not spaces, but entire lines that were added at this point.
So that's what you can achieve by using this add sign for word to use this backslash.
And by the way, for example, here in the string formatting, what this will do is it will create a
new line.
So here it says.
Hello, my name is so you see there is this line, break this backslash and creates a line break if
you were wondering what this backslash and even means.
And verbatim strings are very useful in specific cases.
So let me show you.
So here, instead of using backslash backslash to write file parts, we can use verbatim strings to
make it easier.
So if you remove the ad, you will get an error because you backslash a backslash are not valid escape
characters, for example.
So here you need to have this.
And because otherwise it will think, OK, we're trying to escape something, which means we're trying
to use this backslash you, as we've seen with the backslash end, for example.
Right.
So here we used backslash and well, I got rid of it, but we had this backslash and it would escape
the character and meaning it doesn't consider this backslash and as a character, but it just jumps
to the next line or whatever.
So what this would do in here is it will now give us this particular path and it will give us the dog
photo.
OK, so that's where it is.
Sign is super useful.
So whenever it comes to paths on your machine and then with verbatim strings, even valid escape characters
won't work.
So here, given this backslash and will not do anything, it doesn't have any powers in a verbatim string.
So if we're using that sign here, you can see Moha backslash and you have no powers here, even though
it does have power.
So let me show you in another example.
Without the ads and now we have this backslash and.
Then we will see Wahaha backslash.
You have no powers here, even though I should say you have powers here, for example.
So let's run it again.
And you see Wahaha backslash and you have no powers.
That's where we're using the outside and and Wahaha backslash end, meaning Lambrick.
You have powers here.
All right.
So these are the different ways of string manipulation.
And while for the first three, I would say it makes sense to decide for one of those and to use this
consistently when it comes to verbatim strings, they really have special use cases, as you have seen,
for example, with the location on your PC.
So with the firepower, for example.
All right.
So that's it for this video.
See you in the next one.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.