2 01 Strings
2 01 Strings
Strings
Strings
Escape Description
\\ Backslash
\t Tab
if myString.isEmpty {
print("The string is empty")
}
String basics
Characters
let a = "a" // 'a' is a string
let b: Character = "b" // 'b' is a Character
Concatenation
if month == otherMonth {
print("They are the same")
}
if month != lowercaseMonth {
print("They are not the same.")
}
print(greeting.hasPrefix("Hello"))
print(greeting.hasSuffix("world!"))
print(greeting.hasSuffix("World!"))
true
true
false
String equality and comparison
Finding substrings
let greeting = "Hi Rick, my name is Amy."
if greeting.contains("my name is") {
print("Making an introduction")
}
Making an introduction
String equality and comparison
Checking length
let name = "Ryan Mears"
let count = name.count
let newPassword = "1234"
if newPassword.count < 8 {
print("This password is too short. Passwords should have at least 8 characters.")
}
e is a vowel.
Unicode
1
© 2021 Apple Inc.
This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.