Created
          November 28, 2016 01:49 
        
      - 
      
- 
        Save algal/c21f0dd47c14886ff50d13e6a81f2349 to your computer and use it in GitHub Desktop. 
    Mutating in-place replacement of a substring of a String
  
        
  
    
      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
    
  
  
    
  | // known-good Swift3 | |
| extension String { | |
| /// Performs in-place replacement of first occurence of a substring | |
| mutating func replaceFirstOccurence(of query:String, with replacement:String) { | |
| guard let firstRange = self.range(of: query) | |
| else { return } | |
| self.replaceSubrange(firstRange, with: replacement) | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment