swift基础--字符串截取相关

2019-02-21  本文已影响0人  111ZZzz

1.字符串截取 (用时注意to和from)

后5位

                let str: String = "12345678"

                let end = str.index(str.endIndex, offsetBy: -5)

                self.endTime = str.substring(from: end)

打印:45678

前2位

                let end = str.index(str.startIndex, offsetBy: 3)

                self.endTime = str.substring(to: end)

打印:123 

2.获取字符串长度

let titleString : String = "title"  

let count = titleString.characters.count 

持续更新..

上一篇 下一篇

猜你喜欢

热点阅读