Start learning free

LESSON 65 OF 349 · STRINGS I

Uppercase and Lowercase in Swift in Swift

Lesson

In Swift, String values have built-in methods to change their case:

s.uppercased()   // converts all characters to uppercase
s.lowercased()   // converts all characters to lowercase

Here are some examples:

let word = "Hello World"
let upper = word.uppercased()  // "HELLO WORLD"
let lower = word.lowercased()  // "hello world"

let name = "ALICE"
print(name.lowercased())  // "alice"

These methods return a new String — the original is not modified.


Assignment
Follow the Coding Tutorial and convert word to both uppercase and lowercase!


Hint
Use word.uppercased() and word.lowercased().

STEP 1 OF 2
    Ctrl + Enter to check

    String Upper Lower in Swift

    Keep going with SwiftAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free