How can I remove last character from String variable using Swift? Can\'t find it in documentation.
Here is full example:
var expression = \"45+22\"
e
Swift 4:
let choppedString = String(theString.dropLast())
In Swift 2, do this:
let choppedString = String(theString.characters.dropLast())
I recommend this link to get an understanding of Swift strings.
var str = "bla"
str.removeLast() // returns "a"; str is now "bl"
Use the function removeAtIndex(i: String.Index) -> Character
:
var s = "abc"
s.removeAtIndex(s.endIndex.predecessor()) // "ab"
The easiest way to trim the last character of the string is:
title = title[title.startIndex ..< title.endIndex.advancedBy(-1)]