在 Swift 中,如果有以下字符串:
期望结果:
但是这只返回了4个索引,而不是所有的索引。
你有什么想法吗?
"this is a string"
,如何获得该字符串中字符" "
(空格)所在位置的数组?期望结果:
[4,7,9]
我已经尝试过:let spaces: NSRange = full_string.rangeOfString(" ")
但是这只返回了4个索引,而不是所有的索引。
你有什么想法吗?
searchPattern(" ", inString : " ")
返回Optional([4])
:) - Martin R