What's the best way to cut Swift string into 2-letter-strings?
问题 I need to split a string into 2-letter pieces. Like “friend" -> "fr" "ie" "nd". (Okay, its a step for me to change HEX string to Uint8 Array) My code is for i=0; i<chars.count/2; i++ { let str = input[input.startIndex.advancedBy(i*2)..<input.startIndex.advancedBy(i*2+1)] bytes.append(UInt8(str,radix: 16)!) } But I don't know why I cannot use Range to do this split. And I have no idea what will happen when i*2+1 is bigger than string's length. So what's the best way to cut Swift string into 2