Created
August 29, 2017 18:35
-
-
Save ericjames/06155e1092a508611529a7f70dbf634d to your computer and use it in GitHub Desktop.
Swift 3 - Insert a string inside of a string at a random location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = "123456789abcdefgh" | |
let keyIndex = Int(arc4random_uniform(50)) | |
let newIndex = str.index(str.startIndex, offsetBy: keyIndex) | |
let keyTwo = str.substring(to: newIndex) | |
let keyOne = str.substring(from: newIndex) | |
str = keyTwo + "0000000" + keyOne | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment