Properties2
| Type | Concept |
| Note created | Feb 17, 2025 |
In Swift, strings can include emojis and other UTF-8 characters.
let example = "This is an example of a string ⭐️"
let longerExample = """
Multi-line strings use triple-quotes,
just like Python!
"""Some useful string operations are:
- Use
example.countto get the length of a string. - Use
example.uppercased()to get the string in upper-case letters. - Use
example.hasPrefix(prefix)to check if a string starts with a value (same withexample.hasSuffix(suffix)).
String interpolation
Swift allows for string interpolation using a pretty straightforward syntax:
let name = "Diego"
let age = 27
let message = "Right now, \(name) is \(age) years old."