Miles Morales
Miles Morales

Reputation: 258

How do you turn string value to all caps in Kotlin?

I'm trying to get the popup text for the attack message into all caps, including pre-existing strings from the strings.xml

val playerString = getString( R.string.player )
val monsterString = getString( R.string.monster )

val playerHitMonster = Toast.makeText(this, "$playerString HIT $monsterString FOR $playerDam!", Toast.LENGTH_SHORT)

Is there a way to convert the playerString and monsterString into all caps? ( i.e., "Minotaur" to "MINOTAUR" )

Upvotes: 0

Views: 1446

Answers (2)

Tippu Fisal Sheriff
Tippu Fisal Sheriff

Reputation: 2846

Convert the String to All Caps or All Lower just use this

Solution:

1. yourString.uppercase() // ALL CAPS

2. yourString.lowercase() // all lowers 

Deprecated - Don't use this

  1. yourString.toUpperCase()
  2. yourString.toLowerCase()

Upvotes: 0

Shay Kin
Shay Kin

Reputation: 2667

To convert the String to All Caps just use this :

yourString = yourString.toUpperCase()

and for lower case use :

yourString = yourString.toLowerCase()

Upvotes: 4

Related Questions