我有一个字符串
let stringPlusstring = TextBoxCal.text
我想要得到stringPlusstring的最后一个字符我不想在java上使用数组存在charat,但是我无法在swift上找到这样的关键字
对于Swift 2.x和Swift 3:
let 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 "?"