标签:string
1.删除指定位置的字符串,
let str = "abcdefg"
let str3 = str.substring(from: str.index(str.endIndex, offsetBy: -4))
print(str3)输出defg
let str4 = str.substring(to: str.index(str.startIndex, offsetBy: 4))
print(str4)输出abcd
2、插入字符串
var str = "abcdefg"
str.insert(contentsOf: "****".characters, at: str.index(str.startIndex, offsetBy: 3))
print(str)输出abc****defg
3、更换字符串
var str = "abcdefg"
let str2 = str.replacingOccurrences(of: "ab", with: "")
print(str2)输出cdefg
本文出自 “swift3的常见方法” 博客,请务必保留此出处http://13210199.blog.51cto.com/13200199/1955754
swift3.0常用操作包含删除字符串(string),更换字符串,插入字符串
标签:string
原文地址:http://13210199.blog.51cto.com/13200199/1955754