DEV Community

Sai gowtham
Sai gowtham

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

3 1

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 (1)

Collapse
 
phuongddx profile image
Phuong Doan

Actually when use higher func of Apple it will be eazy! Can implement that func?

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay