To remove the last character of a string in Swift, you can use the dropLast method.
In this example,
str1
with a value of "Hello World"
.var str1 = "Hello World"
str1 = String(str1.dropLast())
print("Modified string is:", str1)
Modified string is: Hello Worl
In this example,
str2
with a value of "apple"
.var str2 = "apple"
str2 = String(str2.dropLast())
print("Modified string is:", str2)
Modified string is: appl
In this tutorial, we learned How to Remove Last Character in a String in Swift language with well detailed examples.