Swift Split String Into Array Of 2 Characters

[Solved] Swift Split String Into Array Of 2 Characters | Swift - Code Explorer | yomemimo.com
Question : swift split string into array of 2 characters

Answered by : shubham-sharma

extension Collection { func unfoldSubSequences(limitedTo maxLength: Int) -> UnfoldSequence<SubSequence,Index> { sequence(state: startIndex) { start in guard start < self.endIndex else { return nil } let end = self.index(start, offsetBy: maxLength, limitedBy: self.endIndex) ?? self.endIndex defer { start = end } return self[start..<end] } } func subSequences(of n: Int) -> [SubSequence] { .init(unfoldSubSequences(limitedTo: n)) }
}
let numbers = "1234567"
let subSequences = numbers.subSequences(of: 2)
print(subSequences) // ["12", "34", "56", "7"]

Source : https://stackoverflow.com/a/48089097/5214671 | Last Update : Thu, 14 Jul 22

Answers related to swift split string into array of 2 characters

Code Explorer Popular Question For Swift