Removing the last character of a string in Swift
In this tutorial, we are going to learn about how to remove the last character of a string in Swift language.
Removing the last character of a string
To remove the last character of a string, we can use the built-in removeLast()
method in Swift.
Here is an example, that removes the last character d
from the following string:
var str = "Fun World"
str.removeLast()
print(str)
Output:
Fun Worl
Note: The
removeLast()
method modifies the original string.
Swift version: 5.1