Swift String – Remove Last Character

To remove last character of a String in Swift, call removeLast() method on this string.

String.removeLast() method removes the last character from the String.

Example

In the following program, we will take a string and remove its last character using removeLast() method.

main.swift

var str = "Hello World"
str.removeLast()
print(str)

Output

Swift String - Remove Last Character
ADVERTISEMENT

Conclusion

In this Swift Tutorial, we learned how to remove the last character of a String in Swift.