Created
July 17, 2017 16:13
-
-
Save dudarenko-io/2b06db38274019e8d5b69587d20c336a to your computer and use it in GitHub Desktop.
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
extension String { | |
/// Finds and returns the range of the first occurrence of a given string within a given left and right occurencies Strings. | |
func rangeBetween(leftStringOccurence: String, rightStringOccurence: String) -> Range<String.Index>? { | |
guard let lowerBound = self.range(of: leftStringOccurence)?.upperBound, | |
let upperBound = self.range(of: rightStringOccurence)?.lowerBound, | |
lowerBound < upperBound else { | |
return nil | |
} | |
return lowerBound..<upperBound | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment