Given a String:
val myString: Any = "baa baa bLack shEEp"
I would like to have a new string (as myString is immutable of course) containing:
BAA BAA BLACK SHEEP
Checked in https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-upper-case.html But it says it is deprecated. I must say - it works, but probably there's a reason for that. Any idea?
CodePudding user response:
the method toUpperCase()
is indeed deprecated. here's an example how to achieve upper case:
val myString: Any = "baa baa bLack shEEp"
if (myString is String){
println(myString.uppercase())
}
CodePudding user response:
simple you just need to do this:
val myString = "baa baa bLack shEEp"
println(myString.uppercase())