swift4 String所遇所致
2018-03-08 本文已影响60人
玉米地里种玉米
![](https://img.haomeiwen.com/i2857740/9dd1d5fdd1c1408a.png)
//得到字符串str 第j个位置上的字符索引
let index = str.index(str.startIndex, offsetBy: j)
//得到当前位置的字符或者字符串
let indexStr:String = String(busNumExcessive[index])
//替换这个位置 的字符或者字符串 str.replaceSubrange(str.index(str.startIndex, offsetBy: j)...str.index(str.startIndex, offsetBy: j), with: replaceStr)
//分割字符串为数组 以某个标记
let array = str.components(separatedBy: ".")
//得到字符串的后四位
str.suffix(4)
//得到字符串的前八位
str.prefix(8)
//拼接字符串
str.append(deviceId)
//得到字符的ASCII码 的int值
code = str.unicodeScalars
num = Int(code.value)
免我惊,免我苦,免我四下流离,免我无枝可依。
—— 仓央嘉措