搜:
swift string range
How To Find A Substring In Range of a Swift String
nsstring – NSRange to Range<String.Index> – Stack Overflow
swift中字符串截取方法(substring) – swift迷
最后用:
substringWithRange(chineseRangeIdx)
完整代码:
extension String { var containsChineseCharacters: Bool { return self.rangeOfString("\\p{Han}", options: .RegularExpressionSearch) != nil } var isAllChineseCharacters: Bool { var isAll = false if let chineseRangeIdx = self.rangeOfString("\\p{Han}.+", options: .RegularExpressionSearch) { print("chineseRangeIdx=\(chineseRangeIdx)") let chineseSubStr = self.substringWithRange(chineseRangeIdx) print("chineseSubStr=\(chineseSubStr)") if chineseSubStr == self { isAll = true } } return isAll } } |
转载请注明:在路上 » [已解决]swift通过Range获取字符串中对应的值