From the course: Android Development Essential Training: The User Interface with Kotlin

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Use string resources with placeholders

Use string resources with placeholders - Android Tutorial

From the course: Android Development Essential Training: The User Interface with Kotlin

Start my 1-month free trial

Use string resources with placeholders

- [Instructor] In Kotlin, you can concatenate strings together using what are known as string templates. A string template is a combination of a literal string plus variables or expressions. When you insert simple variables, you simply prefix them with a $ character, but when you have more complex expressions, for example, if I wanted to use username.toUpperCase, you would have to wrap that in braces. And, notice that when I make that a more complex expression, Android Studio automatically adds the braces around it. So that's one approach for concatenation, but any time you use literal strings in your code, either in your Kotlin code or in an XML layout file, it makes it so you can't localize the string. That is, you can't have multiple versions for different human languages. For that, you once again need string resources. So, I'm going to copy this string, everything inside the quotes, to the clipboard. And then, I'll go to my strings.xml file. I'll create a new string resources…

Contents