作者:手机用户2502937257 | 来源:互联网 | 2023-10-10 10:07
我的需求如下
1
| var s = "helloxxxhelloxxxhelloxxx" |
我已经根据正则匹配出多个hello来 存放在results数组里
1 2 3
| for result in results {
s.stringByReplacingOccurrencesOfString(result, withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
} |
这时候我在遍历的时候希望 把原先字符串中含有hello的字符串给替换成“”, 我希望是每次遍历的时候只替换第一个hello,而不是全部的hello, 这种替换该怎么写呢?