阅读背景:

Swift4.0 字符串操作

来源:互联网 
import UIKit

var str = "Hello, playground"

var index = str.index(of: ",")  //得到空格在字符串中的位置

//Swift 3.0
let greeting = str[str.startIndex ..< index!]  //得到hello
index = str.index(index!, offsetBy: 1)  //空格位置往后移动一位
let name = str[index! ..< str.endIndex]  //playground

//Swift 4.0
//得到hello
let greetings = str.prefix(upTo: index!)
let greetingss = str[..<index!]

//空格位置往后移动一位
index = str.index(index!, offsetBy: 1)

//playground
let names = str.suffix(from: index!)
let namess = str[index!... ]import UIKit

var str = "Hello, playground"

va



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: