Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift split string into array of 2 characters

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"]
Comment

PREVIOUS NEXT
Code Example
Swift :: Swift Character Example 
Swift :: swift extension Array with type 
Swift :: and or in swift 
Swift :: Function Inside Swift Struct 
Swift :: how to add corner in swiftui 
Swift :: swiftui check available ios 
Swift :: swift resource exceeds maximum size 
Swift :: swift create custom button with icon programmatically 
Swift :: swift initialize array with size 
Swift :: swift firebase realtime db class 
Swift :: clothes that you wear in Diwali 
Swift :: printf in swift 
Swift :: swiftui tap gesture 
Swift :: set time programmatically swift 
Swift :: swiftui rectangle top corners radius 
Swift :: swift conditional statements 
Swift :: swift reading binary data 
Swift :: Swift Access Elements from Dictionary 
Swift :: how to check if not running in debufgger swift 
Swift :: Swift guard with multiple conditions 
Swift :: swift dictionary to json string online 
Swift :: swift 1 to n array 
Swift :: octobercms add extra slash to css url 
Swift :: swift closure 
Ruby :: how to get tables list in rails 
Ruby :: find records created in a particular month rails 
Ruby :: ruby constructor 
Ruby :: ruby intersection of two arrays 
Ruby :: safe navigation operator in ruby 
Ruby :: rails add reference 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =