Skip to content

Instantly share code, notes, and snippets.

@harlanhaskins
Created July 26, 2016 23:30
Show Gist options
  • Save harlanhaskins/81bc8bfa6bcb66ea8f613b3c8bda37da to your computer and use it in GitHub Desktop.
Save harlanhaskins/81bc8bfa6bcb66ea8f613b3c8bda37da to your computer and use it in GitHub Desktop.
var str = "Hello, playground"
public extension String {
public func replacing(range: CountableClosedRange<Int>, with replacementString: String) -> String {
let start = characters.index(characters.startIndex, offsetBy: range.lowerBound)
let end = characters.index(start, offsetBy: (range.upperBound + 1) - range.lowerBound)
return self.replacingCharacters(in: start ..< end, with: replacementString)
}
}
str.replacing(range: 0...4, with: "Eyy")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment