制作大块的数组。字符串中的字符

时间:2018-06-13 11:28:07

标签: ios swift

假设我有一个字符串

let string = "ABHJGDFHJWGHJFSHJCKVHDSK"

我需要将输出数组作为["AB","HJ","GD","FH","JW","GH","JF","SH,"JC","KV","HD",SK"]

如何在swift中实现这一目标?

我试过但输出似乎不同

let inputCharacterArray = string.characters.map { $0 }
let pairs = stride(from: 0, to: inputCharacterArray.count, by: 2).map {
    (inputCharacterArray[$0], inputCharacterArray[$0.advanced(by: 1)])
}

0 个答案:

没有答案