Reputation: 65
Im currently developing Kotlin in Android Studio 3.1
out of an JsonReader I receive an String!
, which I'm trying to convert to upper case
so what i do is:
var name=reader.nextString().toUpperCase()
the problem is, that the toUpperCase
is not detected and is marked as unresolved reference
Upvotes: 2
Views: 7770
Reputation: 3365
capitalize Function can do the same as toUpperCase.
fun String.capitalize(): String
Returns a copy of this string having its first letter uppercased, or the original string, if it's empty or already starts with an upper case letter.
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
For more details read the documentation.
Upvotes: -3
Reputation: 39863
The toUpperCase()
method is defined as an inline extension function to String
not as a java.lang.String
. Thus you need to have the Kotlin standard library as your dependency to use this method for String
.
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Upvotes: 5