remove last character from string in swift

To remove the last character from a string in Swift, you can use the removeLast() method or the dropLast() method.

Here's an example using the removeLast() method:

main.swift
var myString = "hello"
myString.removeLast()
print(myString) // Output: "hell"
79 chars
4 lines

And here's an example using the dropLast() method:

main.swift
var myString = "hello"
myString = String(myString.dropLast())
print(myString) // Output: "hell"
96 chars
4 lines

Both methods will modify the original string and return a new string with the last character removed.

gistlibby LogSnag