All language subtitles for 008 String Interpolation_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

In the last section, we spoke about type systems and darte, we're now going to move on to the very

last line of code inside of our program, the print statement right here.

The print function is a built in function that is included for us by default with.

We use this print function to log out any particular value inside of our application.

And so in this case, we are printing out the string.

My name is.

And then this dollar sign name thing right here.

I think overall, the print statement is easy enough and it functions very similar to how print statements

in other languages work as well.

So let's turn our attention just a little bit to the string right here where we put in a dollar sign

name.

This is an example of string interpolation inside of darte.

Whenever Dart sees a dollar sign like this inside of a string, it's going to try to find a variable

defined with the same name as whatever comes directly after that dollar sign.

If Dart is able to find a variable with the same name, it's then going to take the value from that

variable and inject it into the string.

Now, it's just a little bit more complicated than that in some cases when we want to use string interpolation.

So let's talk about one case in which this syntax right here, it doesn't quite work out so well.

As we mentioned just a moment ago in the last section, the string type inside of darte has a length

property associated with it, the returns, the number of characters or that particular string.

So let's try printing out the number of characters inside the name variable right here rather than just

the string itself.

So you might think that we could do a name at length like so.

But if I run this program, you'll notice that I get an output of my name is Steven Length, so definitely

not quite what we're expecting.

The syntax that you're seeing over here for dollar sign and then the variable is only good when we are

printing up some very simple value out of a variable so we can only use dollar sign and the variable

name if we're just referencing the value of that variable and doing nothing else to it.

But if we want to have any type of expression associated with this string interpolation like, say,

looking up at property on a string, then we have to add in a set of curly braces around the entire

expression.

So to get this code right here working, I would have to do a dollar sign, curly brace and then wrap

the entire expression with a set of curly braces like so.

So now if I run this code, I'll see my name is and then seven, which is the number of characters inside

the name variable.

So again, the rule is that if we're printing out just a variable by itself, we can do a dollar sign

and then the variable name.

But if we're going to have any type of expression inside of here, we have to use the curly braces.

Now, just one last thing I want to mention, if you always want to be completely safe and make sure

that this string interpellation always works the way you expect, you can just always choose to use

curly braces like so even if we're just referring to a simple variable.

So if I run this now, I go back to my name is Steven.

So again, if you want to be 100 percent safe all the time, you can just do dollar sign curly braces.

But if you want to be just a little bit fancy, you can certainly omit the curly braces when it's just

a variable.

OK, so that's pretty much it for this code snippet right here.

Let's continue in the next section and we'll continue on our next topic.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.