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
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
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
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.