美文网首页
swift基础--字符串截取相关

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

作者: 111ZZzz | 来源:发表于2019-02-21 14:14 被阅读0次

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 

持续更新..

相关文章

网友评论

      本文标题:swift基础--字符串截取相关

      本文链接:https://www.haomeiwen.com/subject/gymryqtx.html