Skip to content

Instantly share code, notes, and snippets.

@ericjames
Created August 29, 2017 18:35
Show Gist options
  • Save ericjames/06155e1092a508611529a7f70dbf634d to your computer and use it in GitHub Desktop.
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
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