- Kotlin - Home
- Kotlin - Overview
- Kotlin - Environment Setup
- Kotlin - Architecture
- Kotlin - Basic Syntax
- Kotlin - Comments
- Kotlin - Keywords
- Kotlin - Variables
- Kotlin - Data Types
- Kotlin - Operators
- Kotlin - Booleans
- Kotlin - Strings
- Kotlin - Arrays
- Kotlin - Ranges
- Kotlin - Functions
- Kotlin Control Flow
- Kotlin - Control Flow
- Kotlin - if...Else Expression
- Kotlin - When Expression
- Kotlin - For Loop
- Kotlin - While Loop
- Kotlin - Break and Continue
- Kotlin Collections
- Kotlin - Collections
- Kotlin - Lists
- Kotlin - Sets
- Kotlin - Maps
- Kotlin Objects and Classes
- Kotlin - Class and Objects
- Kotlin - Constructors
- Kotlin - Inheritance
- Kotlin - Abstract Classes
- Kotlin - Interface
- Kotlin - Visibility Control
- Kotlin - Extension
- Kotlin - Data Classes
- Kotlin - Sealed Class
- Kotlin - Generics
- Kotlin - Delegation
- Kotlin - Destructuring Declarations
- Kotlin - Exception Handling
Kotlin String - uppercase() Function
The Kotlin string uppercase() function converts all characters of this string to uppercase and return a copy of this string using the rules of the default locale or the specified locale. This function is especially used when working with text processing, user input validation, and formatting.
If the string contains characters that do not have uppercase forms, such as numbers or punctuation marks, they remain unchanged.
This function serves as a replacement for the toUpperCase() function, which has been deprecated.
Syntax
Following is the syntax of the Kotlin string uppercase() function −
fun String.uppercase(locale: Locale): String
Parameters
This function accepts an optional parameter which is a locale object representing the specific locale used for the conversion. If not provided it uses the system's default locale.
Return value
This function returns a string which is upper case of this string.
Example 1: Convert a String into UpperCase
Following is the basic example, we use the uppercase() to make the string upper case −
fun main() {
val string = "tutorialspoint India"
// use uppercase()
val upperCase = string.uppercase()
println("UpperCase of the string: " + upperCase)
}
Output
Following is the output −
UpperCase of the string: TUTORIALSPOINT INDIA
Example 2: Use the UpperCase() with Specific Locale
In this example, we pass the specific locale to the uppercase() function to convert the string into uppercase −
import java.util.Locale
fun main(){
val input = "hello, tutorialspoint!"
val uppercaseString = input.uppercase(Locale.US)
println(uppercaseString)
}
Output
Following is the output −
HELLO, TUTORIALSPOINT!