我有一个字符串
let stringPlusString = TextBoxCal.text
我想要得到stringPlusString的最后一个字符我不想在java上使用数组存在charAt,但是我无法在swift上找到这样的关键字
对于Swift 2.x和Swift 3:
原文链接:https://www.f2er.com/swift/320475.htmllet str = "hello world?" let lastChar = str.characters.last! // lastChar is "?"
对于Swift 1.2:
let str = "hello world?" let lastChar = last(str)! // lastChar is "?"
这适用于Swift 1.2和Swift 2.x:
let str = "hello world?" let lastChar = str[str.endIndex.predecessor()] // lastChar is "?"
对于Swift 3:
let str = "hello world?" let lastChar = str[str.index(before: str.endIndex)] // lastChar is "?"