DEV Community

Sai gowtham
Sai gowtham

Posted on • Updated on • Originally published at reactgo.com

How to remove last character from a string in Swift

To remove the last character from a string we need to use the removeLast() method in swift.

Here is an example that removes the last character d from a string.

var str = "Fun World"

str.removeLast()

print(str)
Enter fullscreen mode Exit fullscreen mode

Output:

Fun Worl
Enter fullscreen mode Exit fullscreen mode

Note: The removeLast() method modifies the original string.

Swift version: 5.1

Top comments (0)